Skip to content

implementation of selector selector method#12582

Open
ash2shukla wants to merge 13 commits intomainfrom
ash2shukla/feat/add-selector-selector-method
Open

implementation of selector selector method#12582
ash2shukla wants to merge 13 commits intomainfrom
ash2shukla/feat/add-selector-selector-method

Conversation

@ash2shukla
Copy link
Contributor

@ash2shukla ash2shukla commented Mar 3, 2026

Resolves #5009
Resolves #10992

Problem

At present selectors can only be used by either setting default selector or passing them via --selector argument. This significantly limits the utility of selectors. We should be able to utilise selectors as just another selector method. This will allow us to cover these functionalities.

Solution

Add a selector selector method class. This will require access to selector definitions and also for recursive calls to get_selected method from node selector. We pass these as extra arguments to SelectorMethod which will be ignored by existing methods but will be used by SelectorSelectorMethod. The selectors is passed from all ResourceTypeSelector so that this can be utilised upstream.

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.

@ash2shukla ash2shukla requested a review from a team as a code owner March 3, 2026 16:12
@cla-bot cla-bot bot added the cla:yes label Mar 3, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2026

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.

@ash2shukla ash2shukla self-assigned this Mar 3, 2026
@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 97.77778% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.39%. Comparing base (8332f46) to head (eb54a0e).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12582      +/-   ##
==========================================
- Coverage   91.39%   91.39%   -0.01%     
==========================================
  Files         203      203              
  Lines       25685    25715      +30     
==========================================
+ Hits        23475    23501      +26     
- Misses       2210     2214       +4     
Flag Coverage Δ
integration 88.27% <97.77%> (-0.02%) ⬇️
unit 65.48% <88.88%> (+0.10%) ⬆️

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

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

MichelleArk
MichelleArk previously approved these changes Mar 4, 2026
Copy link
Contributor

@MichelleArk MichelleArk left a comment

Choose a reason for hiding this comment

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

Nice, neat work!

@ash2shukla ash2shukla added the user docs [docs.getdbt.com] Needs better documentation label Mar 4, 2026
Comment on lines -315 to -389

def test_selector_definition(self):
dct = get_selector_dict(
"""\
selectors:
- name: default
definition:
union:
- intersection:
- tag: foo
- tag: bar
- name: inherited
definition:
method: selector
value: default
"""
)

sel_dict = SelectorDict.parse_from_selectors_list(dct["selectors"])
assert sel_dict
definition = sel_dict["default"]["definition"]
expected = sel_dict["inherited"]["definition"]
self.assertEqual(expected, definition)

def test_selector_definition_with_exclusion(self):
dct = get_selector_dict(
"""\
selectors:
- name: default
definition:
union:
- intersection:
- tag: foo
- tag: bar
- name: inherited
definition:
union:
- method: selector
value: default
- exclude:
- tag: bar
- name: comparison
definition:
union:
- union:
- intersection:
- tag: foo
- tag: bar
- exclude:
- tag: bar
"""
)

sel_dict = SelectorDict.parse_from_selectors_list((dct["selectors"]))
assert sel_dict
definition = sel_dict["inherited"]["definition"]
expected = sel_dict["comparison"]["definition"]
self.assertEqual(expected, definition)

def test_missing_selector(self):
dct = get_selector_dict(
"""\
selectors:
- name: inherited
definition:
method: selector
value: default
"""
)
with self.assertRaises(DbtSelectorsError) as err:
SelectorDict.parse_from_selectors_list((dct["selectors"]))

self.assertEqual(
"Existing selector definition for default not found.", str(err.exception.msg)
)
Copy link
Contributor Author

@ash2shukla ash2shukla Mar 4, 2026

Choose a reason for hiding this comment

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

These tests depend on earlier inheritance behavior which should be removed as part of this feature, as that behavior will not let explicitly declared method: selector be resolved to SelectorSelectorMethod and only - selector:abcd would work.

The missing selector would be raised on runtime because now we can even declare selectors with wildcards.

@akbog
Copy link

akbog commented Mar 10, 2026

Want to raise one risk here (if it hasn't already been raised) - one of the referenced issues describes:

dbt run --selector staging --exclude stg_client

Where dbt behaves "implicitly" by ignoring the --exclude flag. Do we throw any warning or diagnostic to users? If not, I could easily see scheduled jobs with this syntax (we can probably look up the blast radius), where users believe selectors are working together, getting impacted / causing unexpected behavior.

@ash2shukla
Copy link
Contributor Author

Want to raise one risk here (if it hasn't already been raised) - one of the referenced issues describes:

dbt run --selector staging --exclude stg_client

Where dbt behaves "implicitly" by ignoring the --exclude flag. Do we throw any warning or diagnostic to users? If not, I could easily see scheduled jobs with this syntax (we can probably look up the blast radius), where users believe selectors are working together, getting impacted / causing unexpected behavior.

Just to be clear while the issue suggests respecting --exclude and --select with --selector flag, the feature isn't implemented that way. Please have a look at this to see the final scope of the feature that's implemented here.

MichelleArk
MichelleArk previously approved these changes Mar 11, 2026
Copy link
Contributor

@MichelleArk MichelleArk left a comment

Choose a reason for hiding this comment

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

small nit / question but otherwise LGTM!

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

Labels

cla:yes needs_fusion_implementation user docs [docs.getdbt.com] Needs better documentation

Projects

None yet

3 participants