[v2 Bug] dbt check: sources cannot be selected, so checks that report sources are skipped with --select and state:modified
Is this a new bug in dbt v2.x compared to the latest version of dbt 1.x?
- I believe this is a new bug in dbt v2.x
- I have searched the existing issues and could not find a duplicate (closest: #16553, #16503, #15845 — none covers selecting sources in
dbt check)
Current Behavior
dbt check cannot select sources. Any selector that resolves only to sources (source:*, source:raw.unused_table, resource_type:source, a source unique_id) is reported as "does not match any enabled nodes", and state:modified does not see a changed source either. The command then exits 0 without evaluating anything.
The same selectors work in dbt ls, so this is specific to how dbt check scopes the rows of a check, not to node selection in general.
Checks that report sources (a source unique_id in their unique_id column) are therefore never evaluated once a selector is set, for example in a CI job that runs dbt check --select state:modified --state <path>. A pull request that only changes a source can pass without any source check running.
Expected Behavior
A selector that selects sources scopes the rows of checks that report sources, the same way selecting a model scopes the rows of checks that report models. dbt check --select source:raw.unused_table reports that source if the check flags it, and dbt check --select state:modified covers changed sources.
Use case: the dbt-project-evaluator native-check port has 7 checks whose rows are sources (unused sources, sources without freshness, undocumented source tables and sources, duplicate sources, source directories, source fanout). None of them can be used with --select.
Steps To Reproduce
dbt_project.yml
name: repro_source_selection
version: '1.0.0'
profile: repro_source_selection
model-paths: ["models"]
check-paths: ["checks"]
info_schema:
version: 1profiles.yml
repro_source_selection:
target: dev
outputs:
dev:
type: duckdb
path: dev.duckdb
threads: 1models/sources.yml
sources:
- name: raw
description: Raw data.
tables:
- name: orders
- name: unused_tablemodels/stg_orders.sql
select * from {{ source('raw', 'orders') }}checks/unused_source.sql
select unique_id
from {{ info_schema('sources') }}
where unique_id not in (select parent_unique_id from {{ info_schema('edges') }})dbt checkreports the unused source and exits 1:[error] [CheckFailed (dbt1650)]: check 'unused_source' failed with 1 violation(s) │ source.repro_source_selection.raw.unused_table │- Select it, with any of these, and
dbt checkexits 0:dbt check --select 'source:*' dbt check --select 'source:raw.unused_table' dbt check --select 'resource_type:source' dbt check --select 'source.repro_source_selection.raw.unused_table'[warning] [NoNodesForSelectionCriteria (dbt1092)]: The selection criterion 'source:*' does not match any enabled nodes - The selector resolves in
dbt ls:$ dbt ls --select 'source:*' source:repro_source_selection.raw.orders source:repro_source_selection.raw.unused_table - With a source and a model selected, the check is skipped:
$ dbt check unused_source --select 'source:raw.orders+' [warning] [CheckSkipped (dbt1652)]: check 'unused_source' skipped: selection matched no nodes this check can report on - State: run
dbt parseand copytarget/manifest.jsontostate_base/, then addidentifier: orders_v2to theorderstable inmodels/sources.yml.$ dbt ls --select state:modified --state state_base source:repro_source_selection.raw.orders $ dbt check --select state:modified --state state_base [warning] [NoNodesForSelectionCriteria (dbt1092)]: The selection criterion 'state:modified' does not match any enabled nodes
Relevant log output
See the commands above. A model edit under state:modified is scoped correctly (dbt check --select state:modified reports the changed model), so only sources are affected.
What looks like the cause (public source)
Pointers are to dbt-labs/dbt-fusion at 9977b6c (2026-06-04), the most recent public snapshot. The dbt check code is not in that snapshot yet, so that part is described in words; I read a newer tree.
crates/dbt-scheduler/src/schedule.rs(~L289,schedule_graph):Schedule.all_selected_nodeskeeps every selected node, whileSchedule.selected_nodesis built with the comment "Apply exclusions: selected - sources - unused - extended_models", so it never contains sources. That is right for deciding what to run, since sources are not executable.dbt checkbuilds the set of nodes that scope a check's rows fromSchedule.selected_nodes(indbt-main, next to the code that callsscope_for_selection) rather thanSchedule.all_selected_nodes. With a selector that only matches sources, the scope is empty, which is reported as "does not match any enabled nodes". A selector that matches a mix keeps only the non-source ids, so a check whose rows are sources reports nothing and is marked skipped.- Using
all_selected_nodesfor the scope (it also holds the other kindsdbt lsshows) should fix both the source selectors andstate:modifiedfor sources. I did not build the tree to confirm.
Related: #16553 (information schema constraints, found with the same dbt-project-evaluator port).
Environment
- OS: macOS
- CPU: ARM
- dbt distribution and version: dbt 2.0.6
Which database adapter are you using?
duckdb (not adapter-specific)
Source: dbt-labs/dbt-core