Skip to content

[Bug] Bug: YAML parser misapplies inherited tests when using list-merge anchors with overrides #12016

@gracemalirBP

Description

@gracemalirBP

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

When using a YAML anchor for a list of columns and then using the <<: merge key to inherit that list in a model's configuration, the parser incorrectly applies inherited tests. Specifically, a test belonging to one column in the anchor is misapplied to a different column (often the first column in the list or a column being overridden).

Expected Behavior

I am expecting all tests to be inherited from the defined anchor and then the overridden test to run

Steps To Reproduce

Create a schema.yml file with the following content:

YAML

version: 2

x-anchors:
MINIMAL_COLUMNS: &MINIMAL_COLUMNS
- name: TEST
- name: ID
description: "Base ID column."
- name: CONTEXT_STORE
description: "Base store column."
tests:
- accepted_values:
values: ['UK', 'US']

models:

  • name: stg_all_events
    columns:

    Inherit the list

    • <<: *MINIMAL_COLUMNS

    Override the ID column

    • name: ID
      tests:
      • not_null
      • unique
        Run the command: dbt test -s stg_all_events

Expected behavior
The test run should produce three tests applied to their correct columns:

accepted_values on CONTEXT_STORE

not_null on ID

unique on ID

Actual behavior
The test run produces three tests, but the accepted_values test is incorrectly applied to the TEST column (the first column in the anchor) instead of the CONTEXT_STORE column. The following test output is generated:

1 of 3 START test accepted_values_stg_all_events_TEST__UK__US
2 of 3 START test not_null_stg_all_events_ID
3 of 3 START test unique_stg_all_events_ID

Relevant log output

Environment

- OS: macOS
- Python: 3.11.10
- dbt: 1.9.3

Which database adapter are you using with dbt?

snowflake

Additional Context

I have also tried

models:

  • name: stg_all_events
    columns:

    Inherit the list

    • <<: *MINIMAL_COLUMNS
    • name: ID
      data_tests:
      • not_null
      • unique
    • name: CONTEXT_STORE
      tests:
      • accepted_values:
        values: ['UK', 'US']

with the hope that it would override the bug but this results in the same tests as before (that were incorrect) plus the correct store test

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions