-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CT-1923] [Spike] Enforce model contracts for incremental materializations #6755
Comments
@MichelleArk Shall we open a separate issue for enforcing model contracts on view materializations? (Thoughts below, which either should or shouldn't land in that new issue.) Views would only support dbt's "preflight" checks—column names & types—since data platforms don't actually enforce A thing worth considering, when we get to model versions: If you switch a contracted model's materialization from |
+1 for version bump
|
Also: Python models. This issue or a separate issue? We either get this working, for some/all materializations, or we leave this validation error in place: dbt-core/core/dbt/parser/schemas.py Lines 972 to 979 in b5b1699
|
Thinking through this more, incremental materializations might "just work" already because both the initial table creation and temp table creation for updates go through the |
@MichelleArk From our conversation on Monday: This mostly "just works"! One gotcha: We should enforce that all incremental models with Imagine:
Why Upside of this approach: Easy to reason about, document, explain. Downsides of this approach:
|
Makes sense 👍
We should call this out in the migration guide for adapter maintainers. What should the expected behaviour be if Does the variability in adapter support necessarily mean we need to implement this validation in the jinja, so that adapters can overwrite the behaviour (as opposed to earlier on during parsing, perhaps in the |
I also played around with an alternative approach to assert correct model contracts after {% if config.get('contract', False) %}
{{ get_assert_columns_equivalent(get_select_cols_from_relation_query(temp_relation, dest_columns)) }}
{% endif %}
This feels possible but ultimately I prefer the configuration enforcement approach you've outlined @jtcohen6 for a couple reasons:
|
Hmm, not totally sure. I guess I'd hope/expect the adapter to raise an exception or warning (probably in Jinja, within the materialization) if if doesn't support We could:
Line 3 in 7efb6ab
I think we could enforce the validation during parsing, if the only thing we're validating is: if (contract == "true" and materialized == "incremental") and on_schema_change != "append_new_columns" then ValidationError One callout is that the valid options of |
Closing in favor of implementation issue: #7154 |
When
contract
is true, model contracts are enforced prior to table creation for table materializations.Similarly, Incremental models would need to enforce contracts as part of on_schema_change handling, and before the existing table is modified.
The text was updated successfully, but these errors were encountered: