diff --git a/metrics_layer/core/model/view.py b/metrics_layer/core/model/view.py index 578bed4..642dfa8 100644 --- a/metrics_layer/core/model/view.py +++ b/metrics_layer/core/model/view.py @@ -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.", ) ) diff --git a/tests/test_cli.py b/tests/test_cli.py index c06af27..b5917b2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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" ) @@ -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" ) @@ -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" ) @@ -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" ) @@ -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" ) @@ -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" ) diff --git a/tests/test_project_validation.py b/tests/test_project_validation.py index 131fa10..d511bdd 100644 --- a/tests/test_project_validation.py +++ b/tests/test_project_validation.py @@ -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", []),