Repository navigation
fix(tables): keep schemaDefinition when dbt adds a data model - #38285
Conversation
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.
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
Code Review ✅ Approved 🟡 Medium riskChanging table persistence and the source-hash fast path may cause affected tables to be rewritten during ingestion if the lost-field check misfires. Fixes VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Fixes #38427
What
PUT /v1/tables/{id}/dataModeldeleted the table'sschemaDefinition. 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 withincludeDDL.TableRepository.addDataModelread the table withget()for owners, tags, columns and constraints, then wrote the whole row back withdao.update.get()nulls every field it was not asked for, so the write deletedschemaDefinition.dao.updateskips the updater, so no version or change description recorded the loss, andupdatedBy/updatedAtdid not move.tableConstraintsby adding it to the field list.addDataModelnow 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.sourceHashof the ingestion request that carried it. The bulk endpoint then skipped later runs of that table as unchanged, so the definition never came back.sourceHashskip inEntityRepositorynow asks the repository whether the stored row lost a field the request carries (hasLostSourceFields,falseby default).TableRepositoryanswers yes when the request has aschemaDefinitionand the row does not. That table takes the full update, which writes the definition back.Behavior change
schemaDefinition.schemaDefinitionan ingestion request carries is updated even when itssourceHashmatches. Healthy rows are unaffected: whenever the definition differs, the hash already differs too.Not changed here
table_entityon JSON fields that no index backs. The next ingestion run repairs the rows instead.addDataModelstill writes the row withJsonUtils.pojoToJson, notserializeForStorage.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 withexpected: <CREATE VIEW probe_view AS SELECT id FROM probe> but was: <null>.BulkSourceHashFastPathIT#test_matchingSourceHash_storesSchemaDefinitionTheRowLacks: a bulk upsert under the samesourceHashmust store a definition the stored row lacks. Before the fix it failed withbut was: <null>.BulkSourceHashFastPathIT,TableResourceITandTableDataModelCertificationIT(MySQL + Elasticsearch, parallel lane, the focused scopeplan_local_java_tests.pylists): 370 run, 0 failures, 0 errors. The 11 skips are the existingassumeTruecapability gates inBaseEntityIT.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
Keeps
schemaDefinitionwhen dbt attaches a data model and lets ingestion restore definitions lost by earlier writes.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]Reviews (7) · Last reviewed commit: "Merge branch 'main' into fix/datamodel-p..." · Reviewed by Greptile