Skip to content

fix(tables): keep schemaDefinition when dbt adds a data model - #38285

Merged
harshsoni2024 merged 2 commits into
mainfrom
fix/datamodel-put-keeps-schema-definition
Nov 23, 2026
Merged

harshsoni2024 merged 2 commits into
mainfrom
fix/datamodel-put-keeps-schema-definition

Conversation

@harshsoni2024

@harshsoni2024 harshsoni2024 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #38427

What

PUT /v1/tables/{id}/dataModel deleted the table's schemaDefinition. dbt ingestion calls it for every model and source it matches to a table. Each dbt run therefore removed the definition of every dbt-modelled view, and the DDL of every table ingested with includeDDL.

  • TableRepository.addDataModel read the table with get() for owners, tags, columns and constraints, then wrote the whole row back with dao.update.
  • addDataModel now reads the whole stored row (find) and sets the same fields on it. Its merges work as before, and nothing else in the row is lost.
  • A row that lost its definition kept the sourceHash of the ingestion request that carried it. The bulk endpoint then skipped later runs of that table as unchanged, so the definition never came back.
    • The sourceHash skip in EntityRepository now asks the repository whether the stored row lost a field the request carries (hasLostSourceFields, false by default).
    • TableRepository answers yes when the request has a schemaDefinition and the row does not. That table takes the full update, which writes the definition back.

Behavior change

  • A dataModel PUT keeps the table's schemaDefinition.
  • A table whose stored row lacks the schemaDefinition an ingestion request carries is updated even when its sourceHash matches. Healthy rows are unaffected: whenever the definition differs, the hash already differs too.
  • After upgrading, an affected table gets its definition back the next time ingestion sends it. With incremental extraction, that is only the tables a run revisits. One run with incremental extraction off restores all of them.

Not changed here

  • No migration. Finding the affected rows in SQL means scanning table_entity on JSON fields that no index backs. The next ingestion run repairs the rows instead.
  • Serialization: addDataModel still writes the row with JsonUtils.pojoToJson, not serializeForStorage.
  • The 2.0 backport.

Tests

  • TableResourceIT#put_dataModel_keepsSchemaDefinition: ingestion-bot creates a view with a definition, then PUTs a dbt data model, and the definition must survive. Before the fix it failed with expected: <CREATE VIEW probe_view AS SELECT id FROM probe> but was: <null>.
  • BulkSourceHashFastPathIT#test_matchingSourceHash_storesSchemaDefinitionTheRowLacks: a bulk upsert under the same sourceHash must store a definition the stored row lacks. Before the fix it failed with but was: <null>.
  • Full classes: BulkSourceHashFastPathIT, TableResourceIT and TableDataModelCertificationIT (MySQL + Elasticsearch, parallel lane, the focused scope plan_local_java_tests.py lists): 370 run, 0 failures, 0 errors. The 11 skips are the existing assumeTrue capability gates in BaseEntityIT.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Keeps schemaDefinition when dbt attaches a data model and lets ingestion restore definitions lost by earlier writes.

  • Table data-model updates keep saved table definitions.
  • Bulk ingestion restores table definitions even when hashes match.

No actionable issues found. Tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[dbt data model PUT] --> B[Read whole stored table]
  B --> C[Merge data model and tags]
  C --> D[Save table with definition intact]
  E[Bulk ingestion request] --> F{Matching sourceHash?}
  F -->|No| G[Full update]
  F -->|Yes| H{Stored definition missing and incoming definition present?}
  H -->|Yes| G
  H -->|No| I[Skip unchanged table]
Loading

Reviews (7) · Last reviewed commit: "Merge branch 'main' into fix/datamodel-p..." · Reviewed by Greptile

PUT /v1/tables/{id}/dataModel, which dbt ingestion calls for every model
and source it matches to a table, read the table with get() and wrote
the whole row back with dao.update. get() nulls every field it was not
asked for, so each call deleted the table's schemaDefinition: the
definition of every dbt-modelled view, and the DDL of every table
ingested with includeDDL. dao.update skips the updater, so no version or
change description recorded the loss.

addDataModel now reads the whole stored row and sets the same fields on
it, so its merges are unchanged and nothing else in the row is lost.

A row that lost its definition kept the sourceHash of the request that
carried it, so the bulk endpoint skipped later ingestion of that table
as unchanged and the definition never came back. The sourceHash skip no
longer applies to a table whose stored row lacks the schemaDefinition
the request carries, so the next run that sends it writes it back.
@harshsoni2024
harshsoni2024 requested a review from a team as a code owner November 20, 2026 09:05
@harshsoni2024
harshsoni2024 requested review from pmbrull and a balanced review from Copilot November 20, 2026 09:05
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@gitar-bot

gitar-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Changing table persistence and the source-hash fast path may cause affected tables to be rewritten during ingestion if the lost-field check misfires.

Fixes PUT /v1/tables/{id}/dataModel wiping schemaDefinition on every dbt run by having addDataModel read the full stored row via find and update only the intended fields. Also makes the bulk sourceHash fast path re-process rows that lost a schemaDefinition the request carries, so the definition gets restored on next ingestion. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

Copilot AI balanced review requested due to automatic review settings November 23, 2026 05:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

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.

dbt ingestion deletes schemaDefinition via PUT /tables/{id}/dataModel, and re-ingestion skips it as unchanged

3 participants