Skip to content

Conversation

@StevenReitsma
Copy link
Contributor

Summary

When using dbt contracts on incremental models, the column order is not correctly set. This was fixed for table materializations in version 1.5.0, but was never implemented for incremental materializations.

The problem only surfaces when a different ordering is used for the columns in the contract (so in the yaml) compared to the ordering of columns in the actual user sql query. I suspect a relatively low amount of users are using all of contracts, incremental materializations and a non-consistent column order.

With this change, the has_contract variable is added to the incremental materializations, in a similar fashion to the table materialization. The variable is then passed through to the insert_into macro, which already supports correcting inconsistent column ordering by wrapping the user sql in an extra select statement.

Copy link
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 To request another review, post a new comment with "/windsurf-review".

{% endif %}
{%- set inserts_only = config.get('inserts_only') -%}
{%- set grant_config = config.get('grants') -%}
{%- set has_contract = config.get('contract').enforced -%}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The has_contract variable assignment might fail if config.get('contract') returns None. Consider adding a null check similar to how it's done in the table materialization:

Suggested change
{%- set has_contract = config.get('contract').enforced -%}
{%- set has_contract = config.get('contract') is not none and config.get('contract').enforced -%}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant