Skip to content

Commit

Permalink
improve error message for missing or invalid default date (#231)
Browse files Browse the repository at this point in the history
* improve error message for missing or invalid default date

* fix cli test
  • Loading branch information
pblankley authored Aug 23, 2024
1 parent 9616a20 commit a187854
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
19 changes: 14 additions & 5 deletions metrics_layer/core/model/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,23 @@ def collect_errors(self):
),
)
)
except (AccessDeniedOrDoesNotExistException, QueryError):
# If the default date is not joinable to the view (or in the view itself),
# then we need to add an error
if field.view.name not in self.project.get_joinable_views(self.name) + [self.name]:
errors.append(
self._error(
self._definition["default_date"],
(
f"Default date {self.default_date} in view {self.name} is not joinable to the"
f" view {self.name}"
),
)
)
except (QueryError, AccessDeniedOrDoesNotExistException):
errors.append(
self._error(
self._definition["default_date"],
(
f"Default date {self.default_date} in view {self.name} is not joinable to the"
f" view {self.name}"
),
f"Default date {self.default_date} in view {self.name} does not exist.",
)
)

Expand Down
20 changes: 7 additions & 13 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,12 @@ def test_cli_validate(connection, fresh_project, mocker):

# assert result.exit_code == 0
assert (
result.output
== "Found 7 errors in the project:\n\n"
result.output == "Found 7 errors in the project:\n\n"
"\nCould not locate reference revenue_dimension in field total_item_costs in view order_lines\n\n"
"\nField total_item_costs in view order_lines contains invalid field reference revenue_dimension.\n\n"
"\nCould not locate reference revenue_dimension in field revenue_in_cents in view orders\n\n"
"\nCould not locate reference revenue_dimension in field total_revenue in view orders\n\n"
"\nDefault date sessions.session_date in view orders is not joinable to the view orders\n\n"
"\nDefault date sessions.session_date in view orders does not exist.\n\n"
"\nField revenue_in_cents in view orders contains invalid field reference revenue_dimension.\n\n"
"\nField total_revenue in view orders contains invalid field reference revenue_dimension.\n\n"
)
Expand All @@ -500,8 +499,7 @@ def test_cli_validate_broken_canon_date(connection, fresh_project, mocker):

assert result.exit_code == 0
assert (
result.output
== "Found 1 error in the project:\n\n"
result.output == "Found 1 error in the project:\n\n"
"\nCanon date customers.does_not_exist is unreachable in field total_sessions.\n\n"
)

Expand Down Expand Up @@ -758,8 +756,7 @@ def test_cli_validate_model_name_in_view(connection, fresh_project, mocker):

assert result.exit_code == 0
assert (
result.output
== "Found 1 error in the project:\n\n"
result.output == "Found 1 error in the project:\n\n"
"\nCould not find a model in the view orders. Use the model_name property to specify the model.\n\n"
)

Expand Down Expand Up @@ -802,8 +799,7 @@ def test_cli_dashboard_model_does_not_exist(connection, fresh_project, mocker):

assert result.exit_code == 0
assert (
result.output
== "Found 1 error in the project:\n\n"
result.output == "Found 1 error in the project:\n\n"
"\nCould not find or you do not have access to model missing_model in dashboard sales_dashboard\n\n"
)

Expand All @@ -824,8 +820,7 @@ def test_cli_canon_date_inaccessible(connection, fresh_project, mocker):

assert result.exit_code == 0
assert (
result.output
== "Found 1 error in the project:\n\n"
result.output == "Found 1 error in the project:\n\n"
"\nCanon date orders.missing_field is unreachable in field total_revenue.\n\n"
)

Expand Down Expand Up @@ -910,8 +905,7 @@ def test_cli_duplicate_field_names(connection, fresh_project, mocker):

assert result.exit_code == 0
assert (
result.output
== "Found 1 error in the project:\n\n"
result.output == "Found 1 error in the project:\n\n"
"\nDuplicate field names in view customers: number_of_customers\n\n"
)

Expand Down
7 changes: 6 additions & 1 deletion tests/test_project_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,15 @@ def test_validation_with_replaced_model_properties(connection, name, value, erro
1,
["The default_date property, 1 must be a string in the view order_lines"],
),
(
"default_date",
"sessions.session",
["Default date sessions.session in view order_lines is not joinable to the view order_lines"],
),
(
"default_date",
"fake",
["Default date fake in view order_lines is not joinable to the view order_lines"],
["Default date fake in view order_lines does not exist."],
),
("row_label", None, ["The row_label property, None must be a string in the view order_lines"]),
("row_label", "Hello", []),
Expand Down

0 comments on commit a187854

Please sign in to comment.