Skip to content

fix: match bare wildcard FQN selectors against nested leaf names - #16348

Open
itsnamangoyal wants to merge 2 commits into
1.latestfrom
fix/core-937-bare-wildcard-fqn-nested
Open

itsnamangoyal wants to merge 2 commits into
1.latestfrom
fix/core-937-bare-wildcard-fqn-nested

Conversation

@itsnamangoyal

Copy link
Copy Markdown
Contributor

Problem

CORE-937: a bare wildcard FQN selector (e.g. -s "f_*", no dot) fails to match models nested in subfolders — it only matches root-level nodes.

Repro:

dbt ls -s "f_*"   # 74 real f_* models under marts/... -> "No nodes selected!"
dbt ls -s "d_*"   # single root-level d_ model -> matches fine

Root cause

is_selected_node() in core/dbt/graph/selector_methods.py flattens the node's FQN and fnmatchs the entire remaining dotted string against the selector once it hits a wildcard token. For a bare pattern like f_* (no dot), this requires the whole flattened FQN tail (e.g. marts.subdir.f_model) to start with f_, which only holds for root-level nodes whose FQN has no folder segments before the leaf name.

Confirmed this behavior is identical (byte-for-byte function) across 1.10.latest, 1.11.latest, and 1.12.latest — every current v1 branch is affected. dbt Fusion (v2) has carried an explicit "bare wildcard-leaf shortcut" in node_selector.rs since May 2025 (an intentional Fusion-only addition, not something ever ported back to Python) — that's the actual origin of the parity gap, not the PR originally cited in the customer-facing Slack thread (which turned out to be an unrelated path:-selector directory-matching fix).

Fix

In the wildcard-matching branch of is_selected_node, if the existing flatten-and-fnmatch check doesn't match, and the selector is a bare wildcard (no dot), fall back to matching against just the FQN's leaf segment. This is additive — the original whole-FQN match (which also supports matching folder names, e.g. *unions* matching a directory literally named unions) still runs first and is unchanged.

Testing

  • Added test_qualified_name_bare_wildcard_matches_root_leaf (already passed pre-fix) and test_qualified_name_bare_wildcard_matches_nested_leaf (red before, green after) to tests/unit/graph/test_selector_methods.py, exercised through QualifiedNameSelectorMethod.node_is_match — the real production entry point (which also retries against the package-unscoped FQN).
  • Full tests/unit/graph/ + tests/unit/test_graph_selection.py suites (266 tests) pass with no regressions.
  • Live-verified against jaffle-shop with the actual dbt v1 CLI:
    • Before fix: dbt ls -s "stg_*" against the nested models/staging/ folder → No nodes selected!
    • After fix: same command → all 6 stg_* models + their generic tests correctly selected
    • Confirmed no change to path:, dotted-FQN prefix, and exact-match selector forms.

Test plan

  • Unit tests pass (tests/unit/graph/test_selector_methods.py, tests/unit/test_graph_selection.py)
  • Manually reproduced against a live project (jaffle-shop) with and without the fix
  • Changelog entry added via changie new

Copilot AI lite review requested due to automatic review settings September 17, 2026 17:22
@itsnamangoyal
itsnamangoyal requested a review from a team as a code owner September 17, 2026 17:22
@cla-bot cla-bot Bot added the cla:yes label Sep 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Nested versioned models remain unfixed; add matching support and regression coverage.

Pull request overview

Fixes bare wildcard FQN selectors so they match nested model leaf names.

Changes:

  • Adds leaf-level fallback matching for bare wildcards.
  • Adds regression tests for root and nested models.
  • Adds a changelog entry.
File summaries
File Description
tests/unit/graph/test_selector_methods.py Adds wildcard selector regression tests.
core/dbt/graph/selector_methods.py Implements nested leaf matching.
.changes/unreleased/Fixes-20260917-224607.yaml Documents the fix.
Review details

Suppressed comments (1)

core/dbt/graph/selector_methods.py:119

  • This guard leaves nested versioned models unfixed: for an FQN such as ["my_pkg", "marts", "f_model", "v1"], f_* still fails the whole-FQN fnmatch, and the leaf fallback is skipped because is_versioned is true. The fallback should match the model-name segment (fqn[-2]) for versioned nodes, or otherwise explicitly preserve the version suffix while matching the bare pattern; please add a regression test for this case.
        if not is_versioned and "." not in node_selector:
            return fnmatch(fqn[-1], node_selector)
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The fallback still excludes nested versioned models from bare wildcard matching.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread core/dbt/graph/selector_methods.py Outdated
Addresses review feedback on #16348: nested versioned models were
excluded because the fqn's last segment is the version tag (e.g. "v4"),
not the model name.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation preserves existing matching behavior and covers the affected cases with regression tests.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants