Skip to content

Commit

Permalink
Fix handeling partially (in)correct metadata (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
JCZuurmond authored Jun 21, 2024
1 parent 5772be5 commit adc8f08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/databricks/labs/lsql/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ def _get_arguments_parser() -> ArgumentParser:

def _parse_header(self, header: str) -> dict[str, str]:
"""Header is an argparse string."""
header_split = shlex.split(header)
parser = self._get_arguments_parser()
try:
return vars(parser.parse_args(shlex.split(header)))
return vars(parser.parse_args(header_split))
except (argparse.ArgumentError, SystemExit) as e:
logger.warning(f"Parsing {self._path}: {e}")
return {}
return vars(parser.parse_known_args(header_split)[0])

def split(self) -> tuple[str, str]:
"""Split the query file header from the contents.
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ def test_dashboard_handles_incorrect_query_header(tmp_path, caplog):
ws = create_autospec(WorkspaceClient)

# Typo is on purpose
query = "-- --widh 6 --height 3 \nSELECT 82917019218921 AS big_number_needs_big_widget"
query = "-- --widh 6 --height 5 \nSELECT 82917019218921 AS big_number_needs_big_widget"
query_path = tmp_path / "counter.sql"
query_path.write_text(query)

Expand All @@ -828,7 +828,7 @@ def test_dashboard_handles_incorrect_query_header(tmp_path, caplog):

position = lakeview_dashboard.pages[0].layout[0].position
assert position.width == 1
assert position.height == 3
assert position.height == 5
assert query_path.as_posix() in caplog.text
ws.assert_not_called()

Expand Down

0 comments on commit adc8f08

Please sign in to comment.