After upgrading dbt, every run starts with this warning:
[WARNING][MissingArgumentsPropertyInGenericTestDeprecation]: Deprecated
Found top-level arguments to test `accepted_values` defined on 'stg_orders' in
package 'shop' (models/staging/_staging.yml). Arguments to generic tests should
be nested under the `arguments` property.
The tests still run. dbt is asking you to move the test’s arguments, such as values for
accepted_values, one level down, under a new arguments key.
Copy and paste
Before:
- name: status
data_tests:
- accepted_values:
values: ['placed', 'shipped', 'returned']
config:
severity: warn
After:
- name: status
data_tests:
- accepted_values:
arguments:
values: ['placed', 'shipped', 'returned']
config:
severity: warn
Only the arguments move. config stays where it is, and tests without arguments, such as unique and
not_null, do not change.
Fix the whole project automatically:
pip install dbt-autofix
dbt-autofix deprecations --dry-run # show what would change
dbt-autofix deprecations # apply the changes
The same change for other tests
- relationships:
arguments:
to: ref('stg_customers')
field: customer_id
data_tests:
- dbt_utils.unique_combination_of_columns:
arguments:
combination_of_columns: [order_id, line_number]
What dbt-autofix does
On a copy of the example project, the dry run reported two changes:
restructure_yaml_keys
Test 'accepted_values' - Custom test argument 'values' moved under 'arguments'.
changeset_dbt_project_flip_test_arguments_behavior_flag
Set flag 'require_generic_test_arguments_property' to 'True' ...
The flag tells dbt to read arguments as the test’s arguments. In dbt 1.12 it is already on by
default; on older 1.x versions, set it yourself in dbt_project.yml:
flags:
require_generic_test_arguments_property: true
Find every occurrence
dbt shows only the first occurrence of each deprecation. To list them all:
dbt parse --show-all-deprecations --no-partial-parse
Why it changed
With arguments, properties and configuration side by side under a test, dbt could not always tell which
key was which. The arguments property makes it explicit. The new dbt engine (dbt v2) expects that
form, so fixing the warning now also prepares the project for it.
After the change, check that the arguments are really used: in the example, removing returned from
values makes the test fail on the returned orders, as it should.
Tested with dbt Core 1.12 and dbt-autofix 0.22.