Skip to content

Conversation

MichelleArk
Copy link
Contributor

@MichelleArk MichelleArk commented Sep 5, 2025

Resolves #11984

Problem

Adding tags / meta at the column config-level does not make the it through to tag selection for tests.

Solution

🎩 for selection

models:
    name: my_model
    columns:
      - name: customer_id
        description: The unique key of the orders mart.
        data_tests:
          - not_null
          - unique
        config:

          tags: ["test_tag"]
(core) ➜  jaffle-shop git:(main) ✗ dbt ls --select tag:test_tag

19:39:47  Running with dbt=1.11.0-a1
19:39:47  Registered adapter: postgres=1.9.1-a0
19:39:48  Found 93 models, 7 seeds, 2 operations, 59 data tests, 6 sources, 1 exposure, 19 metrics, 1586 macros, 6 semantic models, 3 saved queries, 3 unit tests
jaffle_shop.marts.not_null_customers_customer_id
jaffle_shop.marts.unique_customers_customer_id

🎩 for false positives
In both these situations, running dbt ls state:modified --no-partial-parse

  1. config/meta top-level to start
  • State manifest: with tags/meta at top-level + generated from dbt-core@main
  • Run against: no file changes, on this branch
  1. config/meta config-level to start
  • State manifest: with tags/meta at top-level + generated from dbt-core@main
  • Run against: moving tags/meta to config-level, on this branch

I get 'No nodes selected!', as expected. I've also tested this both on model and source columns, as well as added a test scenario in happy_path_project and this is validated through test.

I've confirmed the manifest.json does change such that config-level vs column-level tags/meta are propagated in either direction, neither influences state:modified selection. column.tags and column.meta does not currently influence state:modified for models or sources (only their own tags/meta do) - even when under config. and changing tags on columns also does not influence state:modified selection of the tests on that column.

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@cla-bot cla-bot bot added the cla:yes label Sep 5, 2025
Copy link
Contributor

github-actions bot commented Sep 5, 2025

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

Copy link

codecov bot commented Sep 5, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.92%. Comparing base (5add25d) to head (f6a03ba).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11992      +/-   ##
==========================================
- Coverage   91.95%   91.92%   -0.03%     
==========================================
  Files         200      200              
  Lines       24451    24468      +17     
==========================================
+ Hits        22483    22493      +10     
- Misses       1968     1975       +7     
Flag Coverage Δ
integration 88.80% <88.88%> (-0.03%) ⬇️
unit 65.32% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 65.32% <50.00%> (-0.02%) ⬇️
Integration Tests 88.80% <88.88%> (-0.03%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MichelleArk MichelleArk marked this pull request as ready for review September 11, 2025 19:52
@MichelleArk MichelleArk requested a review from a team as a code owner September 11, 2025 19:52
@MichelleArk MichelleArk added the backport 1.10.latest Tag for PR to be backported to the 1.10.latest branch label Sep 11, 2025
@jeremyyeo
Copy link
Contributor

jeremyyeo commented Sep 12, 2025

On the topic of source column tests appear to be missing out on this fix

Noticed something interesting when attempting to test "state:modified"...

# models/schema.yml
# Full project: https://github.com/jeremyyeo/dbt-basic/tree/qa-dbt-core-11992
sources:
  - name: public
    tables:
      - name: source_old_way
        columns:
          - name: id
            tags: ["my_tag"]
            tests:
              - not_null
      - name: source_new_way
        columns:
          - name: id
            config:
              tags: ["my_tag"]
            tests:
              - not_null

models:
  - name: mdl_from_old
    columns:
      - name: id
        tags: ["my_tag"]
        tests:
          - not_null
  - name: mdl_from_new
    columns:
      - name: id
        config:
          tags: ["my_tag"]
        tests:
          - not_null

seeds:
  - name: seed_old
    columns:
      - name: id
        tags: ["my_tag"]
        tests:
          - not_null
  - name: seed_new
    columns:
      - name: id
        config:
          tags: ["my_tag"]
        tests:
          - not_null

snapshots:
  - name: snap_old
    relation: ref('seed_old')
    config:
      unique_key: id
      strategy: check
      check_cols: all
    columns:
      - name: id
        tags: ["my_tag"]
        tests:
          - not_null
  - name: snap_new
    relation: ref('seed_new')
    config:
      unique_key: id
      strategy: check
      check_cols: all
    columns:
      - name: id
        config:
          tags: ["my_tag"]
        tests:
          - not_null

4 resource types (source/model/seed/snapshot) - each with a "new way" (tags in config) and an "old way" (tags as top level).

Using main branch:

$ dbt ls -s 'tag:my_tag'
04:13:57  Running with dbt=1.11.0-a1
04:13:57  Registered adapter: postgres=1.9.1-a0
04:13:57  Found 2 models, 2 seeds, 8 data tests, 2 snapshots, 2 sources, 434 macros
analytics.not_null_mdl_from_old_id
analytics.not_null_seed_old_id
analytics.not_null_snap_old_id
analytics.source_not_null_public_source_old_way_id

Using propagate-column-meta-tags branch:

$ dbt ls -s 'tag:my_tag'
04:16:53  Running with dbt=1.11.0-a2
04:16:54  Registered adapter: postgres=1.9.1-a0
04:16:54  Unable to do partial parsing because of a version mismatch
04:16:54  Found 2 models, 2 seeds, 8 data tests, 2 snapshots, 2 sources, 434 macros
analytics.not_null_mdl_from_new_id
analytics.not_null_mdl_from_old_id
analytics.not_null_seed_new_id
analytics.not_null_seed_old_id
analytics.not_null_snap_new_id
analytics.not_null_snap_old_id
analytics.source_not_null_public_source_old_way_id

^ We can see that we list 7 now - missing out on the source_new_way column test...

Ps. I rolled the version to 1.11.0a2 cause my venvs were messed up and I couldn't get this PR to be "installed" properly unless I install and set the version to be different to what main has (1.11.0a1).

Checking the manifest.json generated by 1.11.0a2 (fake bump for this propagate-column-meta-tags branch):

The source-using-the-new-way's test is still missing the top level tag:

    "test.analytics.source_not_null_public_source_new_way_id.4c9bb957a0": {
...
        "tags": [],
...
      },
      "tags": [],
      "description": "",

But (models|seeds|snapshots)-using-the-new-way's test now have that propagated:

    "test.analytics.not_null_mdl_from_new_id.9c4f287810": {
...
        "tags": [],
...
      },
      "tags": ["my_tag"],
      "description": "",

On the topic of "state:modified" false positive

With the caveat of the above issue, it did not appear that this causes any false positives:

$ dbt ls -s state:modified+ --defer --state target_old

04:45:05  Running with dbt=1.11.0-a2
04:45:05  Registered adapter: postgres=1.9.1-a0
04:45:05  Unable to do partial parsing because saved manifest not found. Starting full parse.
04:45:06  Found 2 models, 2 seeds, 8 data tests, 2 snapshots, 2 sources, 434 macros
04:45:06  The selection criterion 'state:modified+' does not match any enabled nodes
04:45:06  No nodes selected!

^ manifest.json in target_old was generated with main.

Other musings

I'm wondering if this is because "source" is a special type of node which we don't parse (since sources aren't really nodes that dbt "builds" per se (dbt doesn't actually materialize sources unlike models/snapshots/seeds))... which is linked to #11973

I put a breakpoint() here:

https://github.com/dbt-labs/dbt-core/blob/propagate-column-meta-tags/core/dbt/parser/schema_generic_tests.py#L375-L386

Just to test some stuff. When I exclusively have source tests in my project... I don't seem to hit this breakpoint - but I do hit it with model tests.

@MichelleArk
Copy link
Contributor Author

@jeremyyeo

^ We can see that we list 7 now - missing out on the source_new_way column test...
Checking the manifest.json generated by 1.11.0a2 (fake bump for this propagate-column-meta-tags branch):
The source-using-the-new-way's test is still missing the top level tag:

Thank you for doing this validation in addition to the false positive check! Turns out source tests were parsed separately and I added some handling for the tag propagation and confirmed + tested selection is working as expected now.

QMalcolm
QMalcolm previously approved these changes Sep 15, 2025
Copy link
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

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

Minor NIT, but good to send it in my opinion 🚀

Copy link
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

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

🚢 🇮🇹

@MichelleArk MichelleArk merged commit b783c97 into main Sep 15, 2025
59 of 61 checks passed
@MichelleArk MichelleArk deleted the propagate-column-meta-tags branch September 15, 2025 18:53
@MichelleArk MichelleArk added backport 1.10.latest Tag for PR to be backported to the 1.10.latest branch and removed backport 1.10.latest Tag for PR to be backported to the 1.10.latest branch labels Sep 15, 2025
github-actions bot pushed a commit that referenced this pull request Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10.latest Tag for PR to be backported to the 1.10.latest branch cla:yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] When using the new format for tags (tags under config), column tests do not inherit the column level tags - causing differences in test selection
3 participants