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

Check if ref'd resource is selected before favoring state #10108

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20240508-151127.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: 'Restore previous behavior for --favor-state: only favor defer_relation if not
selected in current command"'
time: 2024-05-08T15:11:27.510912+02:00
custom:
Author: jtcohen6
Issue: "10107"
7 changes: 5 additions & 2 deletions core/dbt/context/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,11 @@ def create_relation(self, target_model: ManifestNode) -> RelationProxy:
and target_model.defer_relation
and self.config.args.defer
and (
# User has explicitly opted to prefer defer_relation
self.config.args.favor_state
# User has explicitly opted to prefer defer_relation for unselected resources
(
self.config.args.favor_state
and target_model.unique_id not in selected_resources.SELECTED_RESOURCES
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 a global (ew), and has been for a while:

)
# Or, this node's relation does not exist in the expected target location (cache lookup)
or not get_adapter(self.config).get_relation(
target_model.database, target_model.schema, target_model.identifier
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/defer_state/test_defer_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ def test_run_defer_iff_not_exists(self, project, unique_schema, other_schema):
assert len(results) == 2
assert other_schema not in results[0].node.compiled_code

# again with --favor-state, but this time select both the seed and the view
# because the seed is also selected, the view should select from the seed in our schema ('other_schema')
results = run_dbt(
[
"build",
"--state",
"state",
"--select",
"seed view_model",
"--resource-type",
"seed model",
"--defer",
"--favor-state",
"--target",
"otherschema",
]
)
assert len(results) == 2
assert other_schema in results[1].node.compiled_code


class TestDeferStateDeletedUpstream(BaseDeferState):
def test_run_defer_deleted_upstream(self, project, unique_schema, other_schema):
Expand Down
Loading