[Databricks][Fusion] [BLOCKER] Existing table dropped before enforced contract validation
Maintainers usually reply within 6 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 46/100
Research direction
Start by tracing the Databricks table materialization and enforced-contract validation path in the adapter, then compare its operation order with dbt Core and the related issue #13654. Reproduce with an existing populated table and a contract datatype mismatch. Done means failed validation preserves the existing table, and successful replacement does not leave the target missing if creation fails.
Written by the indexing model from the issue text.
Description
Describe the bug
Major blocking issue: dbt Fusion drops an existing populated Databricks table before validating the model's enforced contract.
When running dbt run --select customer, Fusion executes DROP TABLE IF EXISTS against the existing target table before performing contract validation.
If validation fails, the existing table has already been dropped and is completely gone. This happens even though the model run fails and no replacement table is successfully created.
The DROP TABLE IF EXISTS also occurs on runs where the contract is valid.
This makes dbt Fusion unsafe for production use with Databricks table materializations and enforced contracts.
Steps To Reproduce
- Create and populate a Databricks table using a dbt model named
customer, configured withmaterialized='table'and an enforced contract. - Run the model using dbt Fusion.
- Observe that Fusion executes
DROP TABLE IF EXISTSagainst the existing target table. - Change the
sourcecolumn so that the model query returns it asstring, while the enforced contract defines it asboolean. - Run the model again using
dbt run --select customer. - Contract validation detects the datatype mismatch and the run fails.
- Check the target table: the original populated table has been completely dropped.
The same scenario works as expected with dbt Core: contract validation fails, but the existing table is not lost.
Expected behavior
Enforced contract validation should happen before any destructive operation against the existing target table.
If contract validation fails, the existing populated table must remain untouched and available to downstream consumers.
A successful replacement should also use a safe replacement strategy that does not leave the target table missing if validation or creation fails.
Screenshots and log output
Fusion error output:
09:58:53 [ERROR]: in model customer
09:58:53 Compilation Error in model customer
This model has an enforced contract that failed.
Please ensure the name, data_type, and number of columns in your contract match the columns in your model's definition.
| column_name | definition_type | contract_type | mismatch_reason |
| ----------- | --------------- | ------------- | ------------------ |
| source | string | boolean | data type mismatch |
Observed SQL execution order:
Fusion executes:
DROP TABLE IF EXISTS ...
Followed by column/datatype checks and:
CREATE OR REPLACE TABLE ... AS SELECT ...
The contract validation fails with the datatype mismatch shown above, but the original table has already been dropped.
Fusion version:
dbt-fusion 2.0.0-preview.60
Working dbt Core comparison:
Running with dbt=1.12.6
Registered adapter: databricks=1.13.0
System information
The output of dbt --version:
dbt-fusion 2.0.0-preview.60
The operating system you're using:
Windows 11
The output of python --version:
Python 3.12.10
Additional environment details:
- Execution: Databricks SQL Warehouse
- Catalog: Unity Catalog
- Adapter: Databricks
- Adapter version:
1.13.0 - Materialization:
table - Enforced contract:
true - Invocation: VS Code terminal using dbt Fusion
Additional context
This is a major blocking issue for production adoption of dbt Fusion with Databricks.
A normal enforced-contract validation failure can cause an existing production table to disappear. This can break downstream jobs, dashboards, and applications that depend on the table.
The same model and scenario work correctly with dbt Core, so this appears to be specific to the Fusion execution/materialization path.
Related issue: https://github.com/dbt-labs/dbt-core/issues/13654
That issue describes related DROP TABLE IF EXISTS behaviour on Databricks, but this report specifically highlights the destructive impact when enforced-contract validation fails.
- Dominant language
- Python
- Stars
- 391
- Forks
- 231
- Avg merge
- 9d 7h
- Merged PRs (30d)
- 29
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from databricks/dbt-databricks
-
persist_docs.columns triggers a full-plan probe query on views even when the model has no column docsPossibly taken @DelorneN007 claimed this 59 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
databricks/dbt-databricks#1680 · 1 comment ·
Maintainers usually reply within 6 days
-
bug
Difficulty 2/5 Half a day Newbie friendliness 68/100
databricks/dbt-databricks#1003 · 1 comment ·
Maintainers usually reply within 6 days
-
Emit COMMENT and DEFAULT for function arguments and descriptions in CREATE FUNCTIONPossibly taken @alvinism claimed this 7 days ago. Openenhancement
Difficulty 4/5 3-5 days Newbie friendliness 25/100
databricks/dbt-databricks#1764 ·
Maintainers usually reply within 6 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
databricks/dbt-databricks#1761 ·
Maintainers usually reply within 6 days
-
Metadata queries break on catalog, schema or table names containing a quote or backslashPossibly taken @MsMansiDhruv claimed this 14 days ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 55/100
databricks/dbt-databricks#1747 ·
Maintainers usually reply within 6 days
All issues in databricks/dbt-databricks
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
FinanceFlash/unvibecode#699 ·
Maintainers usually reply within 1 day
-
enhancement Website
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OWASP/OWASP-Hunting#96 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
micropython/micropython#19942 ·
Maintainers usually reply within 1 day
-
A rebuild posts "not part of this build" success to the commit's failed `nix-build` gate and effectsPossibly taken @Padraic-O-Mhuiris claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
`epoch.Integer` raises a raw OverflowError for integers too large to convert to a floatPossibly taken @arindam77 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pydantic/pydantic-extra-types#479 ·
Maintainers usually reply within 1 day