Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tests/e2e_dbt_project/macros/generic_tests/test_config_levels.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{% test config_levels(model, expected_config, timestamp_column, time_bucket, where_expression, anomaly_sensitivity, anomaly_direction, days_back, backfill_days, seasonality, min_training_set_size) %}
{%- if execute and elementary.is_test_command() %}
{%- set unexpected_config = [] %}
{%- set model_relation = dbt.load_relation(model) %}

{% set configuration_dict, metric_properties_dict =
elementary.get_anomalies_test_configuration(model_relation,
mandatory_params,
timestamp_column,
where_expression,
anomaly_sensitivity,
anomaly_direction,
min_training_set_size,
time_bucket,
days_back,
backfill_days,
seasonality) %}
Comment on lines +7 to +18
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Find current get_anomalies_test_configuration definitions/call sites =="
rg -n -C3 'get_anomalies_test_configuration\s*\(' -g '*.sql' | head -60

echo
echo "== Find where mandatory_params is defined or set =="
rg -n -C3 '\bmandatory_params\b' -g '*.sql' | head -80

echo
echo "== Inspect the full test_config_levels.sql file =="
cat -n tests/e2e_dbt_project/macros/generic_tests/test_config_levels.sql

Repository: elementary-data/elementary

Length of output: 6115


mandatory_params is undefined and will cause a runtime error.

The macro parameter list does not include mandatory_params (line 1), yet it is passed to elementary.get_anomalies_test_configuration() at line 8. This variable is not defined locally or available in the macro scope, which will cause a compilation/runtime failure when the test executes. Either add mandatory_params to the macro parameters, define it locally before use, or remove it from the function call if it's no longer needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e_dbt_project/macros/generic_tests/test_config_levels.sql` around
lines 6 - 17, The code calls elementary.get_anomalies_test_configuration(...)
with mandatory_params which is undefined; fix by adding mandatory_params as a
parameter to the surrounding macro's signature (or define it locally before the
call) and provide a sensible default (e.g., empty dict) so the call uses a
defined value; update the macro signature where it is declared and ensure the
variable name mandatory_params is passed through to the
elementary.get_anomalies_test_configuration(...) call so that the function
receives a defined argument.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — mandatory_params was available in the original calling context (e.g., test_table_anomalies has mandatory_params=none as a parameter). Since test_config_levels doesn't need mandatory param validation, I've defined it locally as none before the call. Fixed in 9f68a6f.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipped: comment is from another GitHub bot.


{%- set configs_to_test = [('timestamp_column', metric_properties_dict.timestamp_column),
('where_expression', metric_properties_dict.where_expression),
('time_bucket', configuration_dict.time_bucket),
('anomaly_sensitivity', configuration_dict.anomaly_sensitivity),
('anomaly_direction', configuration_dict.anomaly_direction),
('min_training_set_size', configuration_dict.min_training_set_size),
('days_back', configuration_dict.days_back),
('backfill_days', configuration_dict.backfill_days),
('seasonality', configuration_dict.seasonality)
] %}

{%- for config in configs_to_test %}
{%- set config_name, config_value = config %}
{%- set config_check = compare_configs(config_name, config_value, expected_config) %}
{%- if config_check %}
{%- do unexpected_config.append(config_check) -%}
{%- endif %}
{%- endfor %}

{%- if unexpected_config | length > 0 %}
{%- do exceptions.raise_compiler_error('Failure config_levels: ' ~ unexpected_config) -%}
{%- else %}
{#- test must run an sql query -#}
{{ elementary.no_results_query() }}
{%- endif %}
{%- endif %}
{%- endtest %}

{% macro compare_configs(config_name, config, expected_config) %}
{%- if config != expected_config.get(config_name) %}
{%- set unexpected_message = ('For {0} - got config: {1}, expected config: {2}').format(config_name, config, expected_config.get(config_name) ) %}
{{ return(unexpected_message) }}
{%- endif %}
{{ return(none) }}
{% endmacro %}
2 changes: 1 addition & 1 deletion tests/e2e_dbt_project/models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ models:
columns:
- name: "missing_column"
tests:
- uniques:
- unique:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this typo may have been intentional originally, to have an error case for tests
Double check me though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — uniques is intentional. The error_model with missing_column is tagged error_test, and the non-existent uniques test creates a compilation error case that gets validated by the edr monitoring steps. Reverted in f2d740b.

tags: ["error_test", "regular_tests"]

- name: backfill_days_column_anomalies
Expand Down
Loading