Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20260308-163014.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Raise PropertyMovedToConfigDeprecation instead of MissingArgumentsPropertyInGenericTestDeprecation
time: 2026-03-08T16:30:14.0620755Z
custom:
Author: kalluripradeep
Issue: "12572"
21 changes: 18 additions & 3 deletions core/dbt/parser/generic_test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,24 @@ def extract_test_args(
# Extract kwargs when they are nested under new 'arguments' property separately from 'config' if require_generic_test_arguments_property is enabled
if get_flags().require_generic_test_arguments_property:
arguments = test_args.pop("arguments", {})
if not arguments and any(
k not in ("config", "column_name", "description", "name") for k in test_args.keys()
):
for k in test_args.keys():
if k in TestBuilder.CONFIG_ARGS:
deprecations.warn(
"property-moved-to-config-deprecation",
key=k,
file=file_path,
key_path=f"data_tests.{test_name}.{k}",
)

top_level_keys = (
"config",
"column_name",
"description",
"name",
*TestBuilder.CONFIG_ARGS,
)

if not arguments and any(k not in top_level_keys for k in test_args.keys()):
resource = (
f"'{resource_name}' in package '{package_name}'"
if package_name
Expand Down
11 changes: 11 additions & 0 deletions tests/functional/deprecations/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,14 @@ def model(dbt, session):
{{ return(custom_schema_name) }}
{% endmacro %}
"""


generic_test_config_as_top_level_yaml = """
models:
- name: models_trivial
columns:
- name: id
data_tests:
- unique:
where: "valid_to is null"
"""
33 changes: 33 additions & 0 deletions tests/functional/deprecations/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
deprecated_model_exposure_yaml,
duplicate_keys_yaml,
generate_schema_name_null_return_macro_sql,
generic_test_config_as_top_level_yaml,
invalid_deprecation_date_yaml,
models_custom_key_in_config_non_static_parser_sql,
models_custom_key_in_config_sql,
Expand Down Expand Up @@ -949,3 +950,35 @@ def test_python_model_config_additions_dont_raise_deprecations(self, project):
callbacks=[event_catcher.catch],
)
assert len(event_catcher.caught_events) == 0


class TestMissingArgsVsPropertyMovedToConfig:
"""Regression test for #12572 — when a config property like `where` is
defined at the top level of a generic test, it should raise
PropertyMovedToConfigDeprecation, not MissingArgumentsPropertyInGenericTestDeprecation."""

@pytest.fixture(scope="class")
def models(self):
return {
"models_trivial.sql": models_trivial__model_sql,
"models.yml": generic_test_config_as_top_level_yaml,
}

@pytest.fixture(scope="class")
def project_config_update(self):
return {"flags": {"require_generic_test_arguments_property": True}}

def test_config_key_raises_correct_deprecation(self, project):
# Should fire PropertyMovedToConfigDeprecation, not MissingArgumentsPropertyInGenericTestDeprecation
moved_catcher = EventCatcher(PropertyMovedToConfigDeprecation)
missing_catcher = EventCatcher(MissingArgumentsPropertyInGenericTestDeprecation)
run_dbt(
["parse", "--no-partial-parse", "--show-all-deprecations"],
callbacks=[moved_catcher.catch, missing_catcher.catch],
)
assert (
len(moved_catcher.caught_events) == 1
), "Expected PropertyMovedToConfigDeprecation for `where` at top level of generic test"
assert (
len(missing_catcher.caught_events) == 0
), "Got MissingArgumentsPropertyInGenericTestDeprecation — wrong deprecation fired for config key"
Loading