[CT-619] [Bug] Column comparison in snapshot_check_all_get_existing_columns #5222
Labels
adapter_plugins
Issues relating to third-party adapter plugins
bug
Something isn't working
snapshots
Issues related to dbt's snapshot functionality
Team:Adapters
Issues designated for the adapter area of the code
#4893 added a
snapshot_check_all_get_existing_columns
macro, with more complex logic to handle column schema evolution, in cases where a user has simultaneously added a new column to the snapshot query and added it to an explicitcheck_cols
config (i.e. not"all"
).dbt-core/core/dbt/include/global_project/macros/materializations/snapshots/strategies.sql
Lines 106 to 134 in ab0c351
However, this logic depends on comparison between user-provided
check_cols
config to the columns accessed from the database. This doesn't account for quoting/casing differences, which are just about guaranteed on Snowflake. The macro always finds thatcolumn_added
, so snapshots withcheck
strategy + explicitcheck_cols
config always returnwhere TRUE
for theirrow_changed_expr
:dbt-core/core/dbt/include/global_project/macros/materializations/snapshots/strategies.sql
Lines 147 to 151 in ab0c351
Hence, these failing tests: dbt-labs/dbt-snowflake#154
We have two options for refactoring this macro:
check_cols_config
andexisting_cols
check_cols_config
from the database, in all cases, to ensure that casing/quoting will line up exactlyPersonally, I'd opt for the second. It's better to run an extra query than to risk snapshot failure (very bad!). I'm aware that the change in #4893 has us running at least 2 extra queries, relative to the previous behavior for explicit
check_cols
. I don't think it's worth an opt-in config: the principle of the thing is that snapshots shouldn't fail, even if it requires a lot of metadata queries along the way. Worst case, this is user-space code, someone could overridesnapshot_check_all_get_existing_columns
for a more concise (if risky) approach.The text was updated successfully, but these errors were encountered: