Accessing "state" from Jinja context

Hello,

We’re trying to develop a QA test that compares a table in the QA environment with the corresponding table in the Prod environment. The goal here is to check, for example, if some rows are missing from the QA version when we know they should be there (because they are in Prod and we know Prod is correct).

So the question is: when we run dbt build -s my_table --target qa , is it possible to reference the version of my_table that lives in Prod? I’ve tried passing the state from the prod manifest (e.g., dbt build -s my_table --target qa --defer --state /path/to/prod/manifest), but upon inspection of the graph context var, all values of the my_table node point to the QA database/schema, not the prod one.

Am I missing something here? Is it bad practice to do this comparison between QA and Prod in this way?

Thanks!

As of 1.4.0, there is a new --favor-state flag which I think will do what you want. It doesn’t look like it got documented, but check out the issue for it: [CT-470] [Feature] Add option for --defer to favor using --state node even if node exists in current target · Issue #5016 · dbt-labs/dbt-core · GitHub

Documented here: https://docs.getdbt.com/reference/node-selection/defer#favor-state