You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In situations of "deferral," the --favor-state flag should tell dbt to always use the upstream resources defined in the --state manifest, even in cases where that resource has already been materialized in the current (dev/CI) namespace.
While #5859 added the flag appropriately, and the favor_state argument to Manifest.merge_from_artifact, the flag is not actually being piped through the task and into that method. So it never takes effect!
I think this wasn't caught because the old-style integration tests for this functionality were really tricky to read & understand. I only caught this while converting those tests to the new framework (#6616).
Repro case
-- models/model_a.sqlselect1as id
-- models/model_b.sqlselect*from {{ ref('model_a') }}
$ dbt run --target prod
$ mkdir state
$ mv target/manifest.json state/
$ dbt run --target dev
$ dbt run --target dev --select model_b --defer --favor-state --state state/
Because the --favor-state flag was passed, model_bshould select from the "prod" version of model_a, even though it exists in the dev schema. Instead, it still selects from the dev version:
Also in v1.4, we're adding support for --defer to dbt compile + dbt docs generate. (Makes sense!) Let's make sure --favor-state is available on all the same commands as --defer.
[Tech debt] Inconsistent implementation
Also, the way --favor-state was implemented is parallel to --defer, but different from most of our other flags since v1.0:
If set, defer to the state variable for resolving unselected nodes, even if node exist as a database object in the current environment.
""",
disable_help="""
If defer is set, expect standard defer behaviour.
""",
default=flags.FAVOR_STATE_MODE,
)
Let's just solve for this when we move these flags/etc into the new CLI (#6585). We can always add back-compat for the older env vars + flag names — since, in the meantime, some users might add code to their projects like {{ flags.FAVOR_STATE_MODE }}.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
[Bug] [1.4.0rc1] --favor-state not working as intended
[CT-1823] [Bug] [1.4.0rc1] --favor-state not working as intended
Jan 14, 2023
The old integration tests pass with or without the fix for this in ccbdcba — not very helpful!
Whereas, the new converted tests include one (test_defer_state.py::TestRunDeferStateIFFNotExists::test_run_defer_iff_not_exists) that really does fail if I un-commit the changes from ccbdcba.
I'm inclined to keep the fix + the test conversion together, to merge into main + backport to 1.4.latest. That way, we'll actually have a way to know that this new functionality is still working for all v1.4.x releases.
Not working
In situations of "deferral," the
--favor-state
flag should tell dbt to always use the upstream resources defined in the--state
manifest, even in cases where that resource has already been materialized in the current (dev/CI) namespace.While #5859 added the flag appropriately, and the
favor_state
argument toManifest.merge_from_artifact
, the flag is not actually being piped through the task and into that method. So it never takes effect!I think this wasn't caught because the old-style integration tests for this functionality were really tricky to read & understand. I only caught this while converting those tests to the new framework (#6616).
Repro case
Because the
--favor-state
flag was passed,model_b
should select from the "prod" version ofmodel_a
, even though it exists in the dev schema. Instead, it still selects from the dev version:Missing from some relevant tasks
Also in v1.4, we're adding support for
--defer
todbt compile
+dbt docs generate
. (Makes sense!) Let's make sure--favor-state
is available on all the same commands as--defer
.[Tech debt] Inconsistent implementation
Also, the way
--favor-state
was implemented is parallel to--defer
, but different from most of our other flags since v1.0:dbt-core/core/dbt/flags.py
Lines 117 to 118 in 20c95a4
(Namely, the argparse default is set based on the flag, rather than the other way around!)
dbt-core/core/dbt/main.py
Lines 504 to 515 in 20c95a4
Let's just solve for this when we move these flags/etc into the new CLI (#6585). We can always add back-compat for the older env vars + flag names — since, in the meantime, some users might add code to their projects like
{{ flags.FAVOR_STATE_MODE }}
.The text was updated successfully, but these errors were encountered: