Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix][Selection] yaml selector do not obey default overwrite #10009

Merged
merged 5 commits into from
Apr 24, 2024

Conversation

ChenyuLInx
Copy link
Contributor

@ChenyuLInx ChenyuLInx commented Apr 22, 2024

resolves #9776 resolves #7673

Problem

If user define a YAML selector and does not define indirect selection field on it. We would always use the default value eager instead of using the resolved default value of the CLI flag and env vars.(meaning the user cannot overwrite it)
See more detail in #7673

Solution

This patch would cause a selector to default to the resolved value of CLI, env var, specified by user.
This patch also removed the technical debt of always passing an indirect selection field across multiple layers where we should really just do one lookup when a selector is created.

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/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 Apr 22, 2024
Copy link
Contributor

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.

1 similar comment
Copy link
Contributor

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 Apr 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.12%. Comparing base (5c8a4ab) to head (f47407a).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10009      +/-   ##
==========================================
- Coverage   88.16%   88.12%   -0.04%     
==========================================
  Files         181      181              
  Lines       22593    22613      +20     
==========================================
+ Hits        19918    19928      +10     
- Misses       2675     2685      +10     
Flag Coverage Δ
integration 85.44% <100.00%> (-0.04%) ⬇️
unit 62.21% <90.00%> (+0.07%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -121,7 +122,7 @@ def selection_criteria_from_dict(

# If defined field in selector, override CLI flag
indirect_selection = IndirectSelection(
dct.get("indirect_selection", None) or indirect_selection
dct.get("indirect_selection", get_flags().INDIRECT_SELECTION)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the most important change that leads to resolving the bug and also removes all of the variable pass-through.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the motivation for removing the variable pass-through here? I think it could be preferable to call get_flags().INDIRECT_SELECTION in runnable.py to avoid lower-level methods accessing global state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked up all call paths using this variable and all of them are referring to flags. INDIRECT_SELECTION. We can either pass it all the way everywhere or call it once in this lower level function(since this is where the selector being created.).
I think calling once at the lower level is a cleaner implementation overall. Since dbt is built on the assumption of flags is the first thing being constructed during an invocation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, that's fair. I recall from our 'de-globalization' conversations in the past that flags was more acceptable to access because its never mutated and initialized at the very beginning of an invocation, as you mentioned.

"indirect_selection_value,expected_value",
[(v, v) for v in IndirectSelection],
)
def test_selection_criteria_default_indirect_value(indirect_selection_value, expected_value):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New unit test added for this

@@ -92,3 +95,5 @@ def test_setup_event_logger_specify_max_bytes(mocker):
patched_file_handler.assert_called_once_with(
filename="logs/dbt.log", encoding="utf8", maxBytes=1234567, backupCount=5
)
# XXX if we do not clean up event logger here we are going to affect other tests.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something interesting that I noticed.

@ChenyuLInx ChenyuLInx marked this pull request as ready for review April 23, 2024 01:23
@ChenyuLInx ChenyuLInx requested a review from a team as a code owner April 23, 2024 01:23
@ChenyuLInx ChenyuLInx merged commit 9a0b714 into main Apr 24, 2024
64 checks passed
@ChenyuLInx ChenyuLInx deleted the cl/fix_indirect_selection_default branch April 24, 2024 22:43
@adrian-pasek-prv
Copy link

adrian-pasek-prv commented Jun 18, 2024

I think there are still some issues with selectors and indirect-selection flags in v1.8 When using dbt build --selector my_selector --indirect-selection=cautious neither CLI flag nor selector's indirect-selection section overrides DBT_INDIRECT_SELECTION env var. I'm always getting 'indirect_selection': 'eager' in the logs during invocations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants