Skip to content

Materialized views silently ignore contract.enforced: true #1279

@vergenzt

Description

@vergenzt

Describe the bug

When setting +materialized: materialized_view on a model simultaneously with +contract: { enforced: true }, I expected dbt to warn me if my documented column names/types got out of sync with my model SQL... or at least warn me if it's not supported!

I've had it set for a few weeks and just now realized that a model of mine was out of sync. 🙃 I then tested changing the materialization to table in dev and sure enough I got a contract failure.

I vaguely recall noticing that the docs say it's "Models materialized as table, view, and incremental ...", but I think at the time I internally thought that +materialized: materialized_view was essentially a sub-case of +materialized: view so didn't think my use case was excluded.

It seems easy enough to add this to the remaining materialization types for dbt-databricks.

Steps To Reproduce

Create a SQL model with the above configs, with a list of column names/types in my_model.yml which does not match the columns defined in my_model.sql. Call dbt run; it'll succeed with no warnings or errors.

Expected behavior

Either:

  1. something along the lines of ⚠️ [WARNING]: model contract unenforceable on models materialized as 'materialized_view' (models/model.sql), or
  2. Compilation Error in model my_model (models/my_model.sql): Contracted models require data_type to be defined for each column. Please ensure that the column name and data_type are defined within the YAML configuration for the [...] column(s).

System information

The output of dbt --version:

$ dbt --version
WARNING:thrift.transport.sslcompat:using legacy validation callback
Core:
  - installed: 1.10.13
  - latest:    1.10.15 - Update available!

  Your version of dbt-core is out of date!
  You can find instructions for upgrading here:
  https://docs.getdbt.com/docs/installation

Plugins:
  - databricks: 1.10.14 - Update available!
  - spark:      1.9.3   - Up to date!

  At least one plugin is out of date with dbt-core.
  You can find instructions for upgrading here:
  https://docs.getdbt.com/docs/installation

The operating system you're using:
MacOS 15.7.1 (24G231)

The output of python --version:
Python 3.12.5

Additional context

I've (manually) explored the call graph a bit starting from a search in my project's folder (including inclusions from its venv):
Image

From my spelunking it looks like dbt-databricks allows setting up constraints on materialized views -- but won't do the preflight "contract" check to for column names/types consistency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions