Skip to content

Commit 9010537

Browse files
authored
accept generic test args under 'args' (#11840)
1 parent 56d3c93 commit 9010537

File tree

12 files changed

+373
-35
lines changed

12 files changed

+373
-35
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Features
2+
body: Deprecate top-level argument properties in generic tests
3+
time: 2025-07-21T17:31:00.960402-04:00
4+
custom:
5+
Author: michelleark
6+
Issue: "11847"

core/dbt/contracts/project.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ class ProjectFlags(ExtensibleDbtClassMixin):
361361
require_nested_cumulative_type_params: bool = False
362362
validate_macro_args: bool = False
363363
require_all_warnings_handled_by_warn_error: bool = False
364+
require_generic_test_arguments_property: bool = False
364365

365366
@property
366367
def project_only_flags(self) -> Dict[str, Any]:
@@ -376,6 +377,7 @@ def project_only_flags(self) -> Dict[str, Any]:
376377
"require_nested_cumulative_type_params": self.require_nested_cumulative_type_params,
377378
"validate_macro_args": self.validate_macro_args,
378379
"require_all_warnings_handled_by_warn_error": self.require_all_warnings_handled_by_warn_error,
380+
"require_generic_test_arguments_property": self.require_generic_test_arguments_property,
379381
}
380382

381383

core/dbt/deprecations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ class MissingPlusPrefixDeprecation(DBTDeprecation):
215215
_event = "MissingPlusPrefixDeprecation"
216216

217217

218+
class ArgumentsPropertyInGenericTestDeprecation(DBTDeprecation):
219+
_name = "arguments-property-in-generic-test-deprecation"
220+
_event = "ArgumentsPropertyInGenericTestDeprecation"
221+
222+
223+
class MissingArgumentsPropertyInGenericTestDeprecation(DBTDeprecation):
224+
_name = "missing-arguments-property-in-generic-test-deprecation"
225+
_event = "MissingArgumentsPropertyInGenericTestDeprecation"
226+
227+
218228
def renamed_env_var(old_name: str, new_name: str):
219229
class EnvironmentVariableRenamed(DBTDeprecation):
220230
_name = f"environment-variable-renamed:{old_name}"
@@ -298,6 +308,8 @@ def show_deprecations_summary() -> None:
298308
SourceOverrideDeprecation(),
299309
EnvironmentVariableNamespaceDeprecation(),
300310
MissingPlusPrefixDeprecation(),
311+
ArgumentsPropertyInGenericTestDeprecation(),
312+
MissingArgumentsPropertyInGenericTestDeprecation(),
301313
]
302314

303315
deprecations: Dict[str, DBTDeprecation] = {d.name: d for d in deprecations_list}

core/dbt/events/types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,24 @@ def message(self) -> str:
742742
return line_wrap_message(deprecation_tag(description, self.__class__.__name__))
743743

744744

745+
class ArgumentsPropertyInGenericTestDeprecation(WarnLevel):
746+
def code(self) -> str:
747+
return "D038"
748+
749+
def message(self) -> str:
750+
description = f"Found `arguments` property in test definition of `{self.test_name}` without usage of `require_generic_test_arguments_property` behavior change flag. The `arguments` property is deprecated for custom usage and will be used to nest keyword arguments in future versions of dbt."
751+
return line_wrap_message(deprecation_tag(description, self.__class__.__name__))
752+
753+
754+
class MissingArgumentsPropertyInGenericTestDeprecation(WarnLevel):
755+
def code(self) -> str:
756+
return "D039"
757+
758+
def message(self) -> str:
759+
description = f"Found top-level arguments to test `{self.test_name}`. Arguments to generic tests should be nested under the `arguments` property.`"
760+
return line_wrap_message(deprecation_tag(description, self.__class__.__name__))
761+
762+
745763
# =======================================================
746764
# I - Project parsing
747765
# =======================================================

core/dbt/include/jsonschemas/resources/latest.json

Lines changed: 118 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,101 @@
691691
},
692692
"additionalProperties": false
693693
},
694+
"CustomTest": {
695+
"anyOf": [
696+
{
697+
"$ref": "#/definitions/CustomTestMultiKey"
698+
},
699+
{
700+
"type": "object",
701+
"additionalProperties": {
702+
"$ref": "#/definitions/CustomTestInner"
703+
}
704+
}
705+
]
706+
},
707+
"CustomTestInner": {
708+
"type": "object",
709+
"properties": {
710+
"args": {
711+
"anyOf": [
712+
{
713+
"$ref": "#/definitions/AnyValue"
714+
},
715+
{
716+
"type": "null"
717+
}
718+
]
719+
},
720+
"config": {
721+
"anyOf": [
722+
{
723+
"$ref": "#/definitions/DataTestConfig"
724+
},
725+
{
726+
"type": "null"
727+
}
728+
]
729+
},
730+
"description": {
731+
"type": [
732+
"string",
733+
"null"
734+
]
735+
},
736+
"name": {
737+
"type": [
738+
"string",
739+
"null"
740+
]
741+
}
742+
},
743+
"additionalProperties": false
744+
},
745+
"CustomTestMultiKey": {
746+
"type": "object",
747+
"required": [
748+
"test_name"
749+
],
750+
"properties": {
751+
"args": {
752+
"anyOf": [
753+
{
754+
"$ref": "#/definitions/AnyValue"
755+
},
756+
{
757+
"type": "null"
758+
}
759+
]
760+
},
761+
"config": {
762+
"anyOf": [
763+
{
764+
"$ref": "#/definitions/DataTestConfig"
765+
},
766+
{
767+
"type": "null"
768+
}
769+
]
770+
},
771+
"description": {
772+
"type": [
773+
"string",
774+
"null"
775+
]
776+
},
777+
"name": {
778+
"type": [
779+
"string",
780+
"null"
781+
]
782+
},
783+
"test_name": {
784+
"type": "string"
785+
}
786+
},
787+
"additionalProperties": false
788+
},
694789
"DataTestConfig": {
695790
"type": "object",
696791
"properties": {
@@ -1030,7 +1125,6 @@
10301125
]
10311126
},
10321127
"require_partition_filter": {
1033-
"default": false,
10341128
"type": [
10351129
"boolean",
10361130
"null"
@@ -1225,7 +1319,9 @@
12251319
{
12261320
"$ref": "#/definitions/AcceptedValuesTest"
12271321
},
1228-
true
1322+
{
1323+
"$ref": "#/definitions/CustomTest"
1324+
}
12291325
]
12301326
},
12311327
"DbtBatchSize": {
@@ -2234,13 +2330,9 @@
22342330
]
22352331
},
22362332
"offset_window": {
2237-
"anyOf": [
2238-
{
2239-
"$ref": "#/definitions/MetricTimeWindow"
2240-
},
2241-
{
2242-
"type": "null"
2243-
}
2333+
"type": [
2334+
"string",
2335+
"null"
22442336
]
22452337
}
22462338
},
@@ -2287,23 +2379,6 @@
22872379
},
22882380
"additionalProperties": false
22892381
},
2290-
"MetricTimeWindow": {
2291-
"type": "object",
2292-
"required": [
2293-
"count",
2294-
"granularity"
2295-
],
2296-
"properties": {
2297-
"count": {
2298-
"type": "integer",
2299-
"format": "int32"
2300-
},
2301-
"granularity": {
2302-
"type": "string"
2303-
}
2304-
},
2305-
"additionalProperties": false
2306-
},
23072382
"MetricType": {
23082383
"type": "string",
23092384
"enum": [
@@ -3004,7 +3079,6 @@
30043079
]
30053080
},
30063081
"require_partition_filter": {
3007-
"default": false,
30083082
"type": [
30093083
"boolean",
30103084
"null"
@@ -3212,6 +3286,16 @@
32123286
"type": "null"
32133287
}
32143288
]
3289+
},
3290+
"updates_on": {
3291+
"anyOf": [
3292+
{
3293+
"$ref": "#/definitions/UpdatesOn"
3294+
},
3295+
{
3296+
"type": "null"
3297+
}
3298+
]
32153299
}
32163300
},
32173301
"additionalProperties": false
@@ -4139,7 +4223,6 @@
41394223
]
41404224
},
41414225
"require_partition_filter": {
4142-
"default": false,
41434226
"type": [
41444227
"boolean",
41454228
"null"
@@ -4854,7 +4937,6 @@
48544937
]
48554938
},
48564939
"require_partition_filter": {
4857-
"default": false,
48584940
"type": [
48594941
"boolean",
48604942
"null"
@@ -5430,7 +5512,6 @@
54305512
]
54315513
},
54325514
"require_partition_filter": {
5433-
"default": false,
54345515
"type": [
54355516
"boolean",
54365517
"null"
@@ -6149,7 +6230,6 @@
61496230
]
61506231
},
61516232
"require_partition_filter": {
6152-
"default": false,
61536233
"type": [
61546234
"boolean",
61556235
"null"
@@ -6338,6 +6418,13 @@
63386418
},
63396419
"additionalProperties": false
63406420
},
6421+
"UpdatesOn": {
6422+
"type": "string",
6423+
"enum": [
6424+
"any",
6425+
"all"
6426+
]
6427+
},
63416428
"Versions": {
63426429
"type": "object",
63436430
"required": [

core/dbt/parser/generic_test_builders.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from copy import deepcopy
33
from typing import Any, Dict, Generic, List, Optional, Tuple
44

5+
from dbt import deprecations
56
from dbt.artifacts.resources import NodeVersion
67
from dbt.clients.jinja import GENERIC_TEST_KWARGS_NAME, get_rendered
78
from dbt.contracts.graph.nodes import UnpatchedSourceDefinition
@@ -18,6 +19,7 @@
1819
TestTypeError,
1920
UnexpectedTestNamePatternError,
2021
)
22+
from dbt.flags import get_flags
2123
from dbt.parser.common import Testable
2224
from dbt.utils import md5
2325
from dbt_common.exceptions.macros import UndefinedMacroError
@@ -227,6 +229,20 @@ def extract_test_args(data_test, name=None) -> Tuple[str, Dict[str, Any]]:
227229
test_args = deepcopy(test_args)
228230
if name is not None:
229231
test_args["column_name"] = name
232+
233+
# Extract kwargs when they are nested under new 'arguments' property separately from 'config' if require_generic_test_arguments_property is enabled
234+
if get_flags().require_generic_test_arguments_property:
235+
arguments = test_args.pop("arguments", {})
236+
if not arguments and any(k not in ("config", "column_name") for k in test_args.keys()):
237+
deprecations.warn(
238+
"missing-arguments-property-in-generic-test-deprecation", test_name=test_name
239+
)
240+
test_args = {**test_args, **arguments}
241+
elif "arguments" in test_args:
242+
deprecations.warn(
243+
"arguments-property-in-generic-test-deprecation", test_name=test_name
244+
)
245+
230246
return test_name, test_args
231247

232248
def tags(self) -> List[str]:

core/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
# Minor versions for these are expected to be backwards-compatible
7575
"dbt-common>=1.27.0,<2.0",
7676
"dbt-adapters>=1.15.2,<2.0",
77-
"dbt-protos>=1.0.339,<2.0",
77+
"dbt-protos>=1.0.346,<2.0",
7878
"pydantic<3",
7979
# ----
8080
# Expect compatibility with all new versions of these packages, so lower bounds only.

0 commit comments

Comments
 (0)