Snowflake-Labs / dbt_constraints

This package generates database constraints based on the tests in a dbt project
Apache License 2.0
139 stars 27 forks source link

Deferral seems broken when using dbt 1.7 #70

Open jfmario opened 1 month ago

jfmario commented 1 month ago

We are running into an issue when dbt_constraints is creating constraints based on the dbt_utils relationships test.

It does not respect environment deferral when running in dbt 1.8 with state:modified+. It tries to enforce a relationship between a model in the CI schema another model (from earlier in the DAG) which does not exist in the CI schema (it should defer to the one in the target schema).

This only happened when using dbt 1.8. When I reverted to dbt 1.6, everything worked as expected.

jfmario commented 1 month ago

Correction on the above: version 1.8 is the version we're struggling with.

sfc-gh-dflippo commented 1 month ago

Could you please verify whether version 1.0.0, just released a few minutes ago, has the same issue? A lot of the logic has been updated to support the new RELY and NORELY features and it is possible that another change fixed this issue. I don't currently have any integration tests that use the new Defer feature so I'll have to first incorporate that to identify why it is using the wrong table for the foreign key constraints.

janpetterholmberg commented 1 month ago

I got this error today, which is strange since we have kept the dbt_constraints version; we are still using 0.6.3. I updated it to version 1.0.2 and tested it, but the error still happens. We are using dbt cloud version less the whole time and are currently on dbt version 1.8

We have a CI environment that deferes to production.

From the debug log: SHOW COLUMNS IN TABLE DBT_CI.dbt_cloud_pr_171714_143.displaygrade 2024-08-02 12:47:44.749742 (MainThread): 12:47:44 Snowflake adapter: Snowflake query id: 01b6149f-0304-481f-0001-2502b621b3a3 2024-08-02 12:47:44.750583 (MainThread): 12:47:44 Snowflake adapter: Snowflake error: 002003 (42S02): SQL compilation error: Table 'DBT_CI.DBT_CLOUD_PR_171714_143.DISPLAYGRADE' does not exist or not authorized. 2024-08-02 12:47:44.763415 (MainThread): 12:47:44 Database error while running on-run-end

DISPLAYGRADE is a seed upstream from the artifacts being built, so the object does not exist in the CI schema and should not exist there.

jfmario commented 1 month ago

Note that I'm still seeing this as of 1.0.2.