diff --git a/integration_tests/tests/test_anomalies_exclude_dates.py b/integration_tests/tests/test_anomalies_exclude_dates.py index 88ca3e936..2dfeacd8d 100644 --- a/integration_tests/tests/test_anomalies_exclude_dates.py +++ b/integration_tests/tests/test_anomalies_exclude_dates.py @@ -151,3 +151,9 @@ def test_invalid_configurations(test_id: str, dbt_project: DbtProject): test_id, DBT_TEST_NAME, test_args, test_column="metric" ) assert test_result["status"] == "error" + + test_args = {**DBT_TEST_ARGS, "anomalies_exclude_dates": {"after": "2023-10-01"}} + test_result = dbt_project.test( + test_id, DBT_TEST_NAME, test_args, test_column="metric" + ) + assert test_result["status"] == "error" diff --git a/macros/edr/tests/test_configuration/get_anomalies_exclude_dates.sql b/macros/edr/tests/test_configuration/get_anomalies_exclude_dates.sql index 368e0feac..c0b74108d 100644 --- a/macros/edr/tests/test_configuration/get_anomalies_exclude_dates.sql +++ b/macros/edr/tests/test_configuration/get_anomalies_exclude_dates.sql @@ -14,8 +14,14 @@ {% if value is string %} {% do dates_in_config.append(value) %} {% elif value is mapping %} + {# Don't allow ranges without "before" #} + {% if "before" not in value %} + {% do elementary.raise_anomalies_exclusion_dates_invalid_format_error() %} + {% endif %} + + {# Make sure "after" and "before" are the only allowed keys #} {% for key, val in value.items() %} - {% if key not in ["before", "after"] %} + {% if key not in ["after", "before"] %} {% do elementary.raise_anomalies_exclusion_dates_invalid_format_error() %} {% endif %} {% do dates_in_config.append(val) %} @@ -35,7 +41,8 @@ {% macro raise_anomalies_exclusion_dates_invalid_format_error() %} {% do exceptions.raise_compiler_error( " -Invalid detection_delay format. Expected format is a list of either dates or date ranges, for example: +Invalid detection_delay format. Expected format is a list of either dates or date ranges. Below are +examples of the supported options: anomalies_exclude_dates: - 2023-10-01 # Specific date