-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feature/favor-state-node #5859
feature/favor-state-node #5859
Changes from all commits
a3726d5
2ab0291
4b6d910
a5e77ff
166fb1d
e428cd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
kind: Features | ||
body: Added favor-state flag to optionally favor state nodes even if unselected node | ||
exists | ||
time: 2022-04-08T16:54:59.696564+01:00 | ||
custom: | ||
Author: daniel-murray josephberni | ||
Issue: "2968" | ||
PR: "5859" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,9 @@ def run_and_snapshot_defer(self): | |
# defer test, it succeeds | ||
results = self.run_dbt(['snapshot', '--state', 'state', '--defer']) | ||
|
||
# favor_state test, it succeeds | ||
results = self.run_dbt(['snapshot', '--state', 'state', '--defer', '--favor-state']) | ||
|
||
def run_and_defer(self): | ||
results = self.run_dbt(['seed']) | ||
assert len(results) == 1 | ||
|
@@ -123,6 +126,40 @@ def run_and_defer(self): | |
|
||
assert len(results) == 1 | ||
|
||
def run_and_defer_favor_state(self): | ||
results = self.run_dbt(['seed']) | ||
assert len(results) == 1 | ||
assert not any(r.node.deferred for r in results) | ||
results = self.run_dbt(['run']) | ||
assert len(results) == 2 | ||
assert not any(r.node.deferred for r in results) | ||
results = self.run_dbt(['test']) | ||
assert len(results) == 2 | ||
|
||
# copy files over from the happy times when we had a good target | ||
self.copy_state() | ||
|
||
# test tests first, because run will change things | ||
# no state, wrong schema, failure. | ||
self.run_dbt(['test', '--target', 'otherschema'], expect_pass=False) | ||
|
||
# no state, run also fails | ||
self.run_dbt(['run', '--target', 'otherschema'], expect_pass=False) | ||
|
||
# defer test, it succeeds | ||
results = self.run_dbt(['test', '-m', 'view_model+', '--state', 'state', '--defer', '--favor-state', '--target', 'otherschema']) | ||
|
||
# with state it should work though | ||
results = self.run_dbt(['run', '-m', 'view_model', '--state', 'state', '--defer', '--favor-state', '--target', 'otherschema']) | ||
assert self.other_schema not in results[0].node.compiled_code | ||
assert self.unique_schema() in results[0].node.compiled_code | ||
|
||
with open('target/manifest.json') as fp: | ||
data = json.load(fp) | ||
assert data['nodes']['seed.test.seed']['deferred'] | ||
|
||
assert len(results) == 1 | ||
|
||
def run_switchdirs_defer(self): | ||
results = self.run_dbt(['seed']) | ||
assert len(results) == 1 | ||
|
@@ -152,6 +189,35 @@ def run_switchdirs_defer(self): | |
expect_pass=False, | ||
) | ||
|
||
def run_switchdirs_defer_favor_state(self): | ||
results = self.run_dbt(['seed']) | ||
assert len(results) == 1 | ||
results = self.run_dbt(['run']) | ||
assert len(results) == 2 | ||
|
||
# copy files over from the happy times when we had a good target | ||
self.copy_state() | ||
|
||
self.use_default_project({'model-paths': ['changed_models']}) | ||
# the sql here is just wrong, so it should fail | ||
self.run_dbt( | ||
['run', '-m', 'view_model', '--state', 'state', '--defer', '--favor-state', '--target', 'otherschema'], | ||
expect_pass=False, | ||
) | ||
# but this should work since we just use the old happy model | ||
self.run_dbt( | ||
['run', '-m', 'table_model', '--state', 'state', '--defer', '--favor-state', '--target', 'otherschema'], | ||
expect_pass=True, | ||
) | ||
|
||
self.use_default_project({'model-paths': ['changed_models_bad']}) | ||
# this should fail because the table model refs a broken ephemeral | ||
# model, which it should see | ||
self.run_dbt( | ||
['run', '-m', 'table_model', '--state', 'state', '--defer', '--favor-state', '--target', 'otherschema'], | ||
expect_pass=False, | ||
) | ||
|
||
def run_defer_iff_not_exists(self): | ||
results = self.run_dbt(['seed', '--target', 'otherschema']) | ||
assert len(results) == 1 | ||
|
@@ -169,6 +235,23 @@ def run_defer_iff_not_exists(self): | |
assert self.other_schema not in results[0].node.compiled_code | ||
assert self.unique_schema() in results[0].node.compiled_code | ||
|
||
def run_defer_iff_not_exists_favor_state(self): | ||
results = self.run_dbt(['seed']) | ||
assert len(results) == 1 | ||
results = self.run_dbt(['run']) | ||
assert len(results) == 2 | ||
|
||
# copy files over from the happy times when we had a good target | ||
self.copy_state() | ||
results = self.run_dbt(['seed']) | ||
assert len(results) == 1 | ||
results = self.run_dbt(['run', '--state', 'state', '--defer', '--favor-state', '--target', 'otherschema']) | ||
assert len(results) == 2 | ||
|
||
# because the seed exists in other schema, we should defer it | ||
assert self.other_schema not in results[0].node.compiled_code | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this is the line causing the tests to fail 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was creating the seed in the other_schema and checking it wasn't there, resolved this. If all OK will squash commits. |
||
assert self.unique_schema() in results[0].node.compiled_code | ||
|
||
def run_defer_deleted_upstream(self): | ||
results = self.run_dbt(['seed']) | ||
assert len(results) == 1 | ||
|
@@ -191,6 +274,27 @@ def run_defer_deleted_upstream(self): | |
assert self.other_schema not in results[0].node.compiled_code | ||
assert self.unique_schema() in results[0].node.compiled_code | ||
|
||
def run_defer_deleted_upstream_favor_state(self): | ||
results = self.run_dbt(['seed']) | ||
assert len(results) == 1 | ||
results = self.run_dbt(['run']) | ||
assert len(results) == 2 | ||
|
||
# copy files over from the happy times when we had a good target | ||
self.copy_state() | ||
|
||
self.use_default_project({'model-paths': ['changed_models_missing']}) | ||
|
||
self.run_dbt( | ||
['run', '-m', 'view_model', '--state', 'state', '--defer', '--favor-state', '--target', 'otherschema'], | ||
expect_pass=True, | ||
) | ||
|
||
# despite deferral, test should use models just created in our schema | ||
results = self.run_dbt(['test', '--state', 'state', '--defer', '--favor-state']) | ||
assert self.other_schema not in results[0].node.compiled_code | ||
assert self.unique_schema() in results[0].node.compiled_code | ||
|
||
@use_profile('postgres') | ||
def test_postgres_state_changetarget(self): | ||
self.run_and_defer() | ||
|
@@ -199,18 +303,38 @@ def test_postgres_state_changetarget(self): | |
with pytest.raises(SystemExit): | ||
self.run_dbt(['seed', '--defer']) | ||
|
||
@use_profile('postgres') | ||
def test_postgres_state_changetarget_favor_state(self): | ||
self.run_and_defer_favor_state() | ||
|
||
# make sure these commands don't work with --defer | ||
with pytest.raises(SystemExit): | ||
self.run_dbt(['seed', '--defer']) | ||
|
||
@use_profile('postgres') | ||
def test_postgres_state_changedir(self): | ||
self.run_switchdirs_defer() | ||
|
||
@use_profile('postgres') | ||
def test_postgres_state_changedir_favor_state(self): | ||
self.run_switchdirs_defer_favor_state() | ||
|
||
@use_profile('postgres') | ||
def test_postgres_state_defer_iffnotexists(self): | ||
self.run_defer_iff_not_exists() | ||
|
||
@use_profile('postgres') | ||
def test_postgres_state_defer_iffnotexists_favor_state(self): | ||
self.run_defer_iff_not_exists_favor_state() | ||
|
||
@use_profile('postgres') | ||
def test_postgres_state_defer_deleted_upstream(self): | ||
self.run_defer_deleted_upstream() | ||
|
||
@use_profile('postgres') | ||
def test_postgres_state_defer_deleted_upstream_favor_state(self): | ||
self.run_defer_deleted_upstream_favor_state() | ||
|
||
@use_profile('postgres') | ||
def test_postgres_state_snapshot_defer(self): | ||
self.run_and_snapshot_defer() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iknox-fa Do you have a sense of how we want to handle new flag additions, while we're migrating from old to new CLI? Since the new CLI is checked into
main
, we could ask folks to add it here — but we'll probably also need to check for parity again before formally cutting over in a few monthsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this the other day @jtcohen6. I don't have a strong feeling about this-- if we add this flag to the new CLI in this PR I'd be thrilled, but ultimately the "last stop" for this would be when we implement the Click version of the
run
task (#5551).