Repository navigation
fix(csv): restore FK RELATED_TO edge on recursive/bulk import - #32113
Conversation
The bulk relationship path was asymmetric for tables: clearEntitySpecificRelationshipsForMany deletes both the schema CONTAINS edge and the foreign-key RELATED_TO (ER) edge, but storeEntitySpecificRelationshipsForMany only re-added CONTAINS. So on a recursive CSV import (and bulk create), a table's FK relationship to its referenced table disappeared even though the tableConstraints JSON was preserved. The single-entity path is unaffected (storeEntity -> addConstraintRelationship), which is why non-recursive imports kept the edge. Fix: after the bulk CONTAINS insert, re-add the constraint RELATED_TO edges via addConstraintRelationship, mirroring the single-entity store path. Test: DatabaseServiceResourceIT#test_importExportRecursive_preservesTableConstraints now also asserts the RELATED_TO edge survives a recursive round trip (read from the DAO, not the eventually-consistent search endpoint). Verified before/after on a live stack: without the fix the edge is dropped, with the fix it survives.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Addresses two review points on the initial fix: - N+1: the per-table addConstraintRelationship() did a getEntityReferenceByName lookup and a single addRelationship insert per foreign key. Replaced with buildConstraintRelationships(), which resolves all referred tables in one findByNames() query and folds the RELATED_TO edges into the caller's existing bulkInsertRelationships() call -- no per-FK query or insert. - Cross-chunk forward reference (greptile P1): addConstraintRelationship() resolved the referred table eagerly and threw EntityNotFoundException when the target was created later in another bulk chunk, failing the source table with BAD_REQUEST. The batched resolver skips a referred table that is not yet persisted instead of throwing, so a forward reference cannot fail the request. The edge is best-effort in the bulk path and is created whenever the target already exists -- always true for a recursive re-import of existing tables, the case that regressed. Duplicate edges are harmless (bulkInsertTo is INSERT IGNORE / ON CONFLICT DO NOTHING). Re-verified: recursive-import edge IT still GREEN, and live before/after confirms the FK edge survives a recursive import.
✅ Playwright Results — workflow succeededValidated commit ✅ 4484 passed · ❌ 0 failed · 🟡 4 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 54m 20s ⏱️ Max setup 6m 1s · max shard execution 22m 58s · max shard-job elapsed before upload 26m 9s · reporting 17s 🌐 217.57 requests/attempt · 2.31 app boots/UI scenario · 35.27% common-shard skew Optimization targets still in progress:
🟡 4 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
|
This PR has had no activity for 30 days and will be closed in 7 days if no further activity occurs. |
Referred tables already in the batch (the common recursive-import case) are resolved from memory, so only out-of-batch targets hit findByNames. Also walks constraints once and dedupes composite-FK targets per table.
Code Review ✅ Approved🔴 High risk · Batched FK edge restoration changes persisted relationship data; skipping targets absent from the batch and database may leave ER links missing. Restores the foreign-key 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 |
…on recursive CSV import (#37244) * Fixes #31857, #31858: preserve table constraints and column custom properties on recursive CSV import (#31863) * Fixes #31857: preserve table constraints on recursive CSV import createTableEntity fetched the existing table without tableConstraints/ tablePartition, so the subsequent createOrUpdate persisted them as null and the recursive CSV import silently dropped every table's PK/UNIQUE/FK. Load those fields so they carry through unchanged. Adds DatabaseServiceResourceIT.test_importExportRecursive_preservesTableConstraints. * test: cover FOREIGN_KEY (ER) in recursive CSV constraint round trip Adds a referenced table and a FOREIGN_KEY constraint (with referredColumns) so the recursive round trip also asserts the referenced-table linkage survives, not just PRIMARY_KEY/UNIQUE. * Fixes #31858: preserve column custom properties on recursive CSV import createTableEntity fetched the table with "extension" but not "columns"; TableRepository.setFields only hydrates column.extension when both fields are requested, so the recursive table-row createOrUpdate persisted columns with null extension and dropped column custom properties before the column rows patched back. Add "columns" to the fetch so column extension is hydrated and carried through. Adds DatabaseServiceResourceIT.test_importExportRecursive_preservesColumnCustomProperties. Verified: 3 recursive round-trip ITs pass (constraints+FK, column custom properties, and the pre-existing column tags/glossary test) — Tests run: 3, Failures: 0, Errors: 0. * test: update EntityCsvTest mock stub for new createTableEntity fetch fields createTableEntity now fetches tableConstraints,tablePartition,columns; the unit test stubbed getEntityWithDependencyResolution on the exact old field string, so the stub stopped matching and returned null -> NPE. Update the stub to the new field string. EntityCsvTest: Tests run: 65, Failures: 0. * Fixes #31858: preserve column custom properties via targeted removeExtensions The complete fix. The bulk import update path (updateManyEntitiesForImport) called removeExtensions(originals), which did a blanket entityExtensionDAO.deleteAllBatch(id) -- deleting EVERY entity_extension row for a table (including its columnExtension rows) whenever the entity carried table-level extension -- then re-stored only the table-level extension. So a recursive CSV import of a table that had BOTH table-level and column-level custom properties silently dropped the column custom properties. Make removeExtensions targeted, mirroring the single-entity removeExtension() (delete only the entity's own custom-property rows), so columnExtension rows are no longer collateral-deleted. Also revert the earlier createTableEntity 'columns' fetch addition (it only masked the column-only case; the real defect was the blanket delete above) -- the fetch keeps tableConstraints,tablePartition for #31857. Strengthen DatabaseServiceResourceIT.test_importExportRecursive_preservesColumnCustomProperties to define + set a table-level custom property alongside column-level ones, so the regression (which only manifests when both are present) can't false-green. Verified live on a 2.0 stack: recursive export->import at table/schema/database/ service now preserves table + column custom properties AND table constraints; EntityCsvTest 65/0; the 3 recursive ITs pass. * perf(csv-import): batch removeExtensions custom-property delete (avoid N+1) The prior fix looped removeExtension(entity) per entity, which fires one DELETE per custom-property field -- an N+1 for bulk imports of many entities. Restore a single batched delete but scope it to the entity's own custom-property rows via a new jsonSchema-filtered DAO batch: DELETE FROM entity_extension WHERE id IN (<ids>) AND jsonSchema = 'customFieldSchema' run one statement per chunk (updateInChunks). This keeps columnExtension (and version) rows untouched -- so column custom properties still survive a bulk import that updates table-level extension -- without the per-field N+1. Verified: EntityCsvTest 65/0; DatabaseServiceResourceIT recursive tests 0 fail (incl. table+column custom properties); ColumnCustomPropertiesIT 30/0. (cherry picked from commit 0a603cd) * fix(csv): restore FK RELATED_TO edge on recursive/bulk import The bulk relationship path was asymmetric for tables: clearEntitySpecificRelationshipsForMany deletes both the schema CONTAINS edge and the foreign-key RELATED_TO (ER) edge, but storeEntitySpecificRelationshipsForMany only re-added CONTAINS. So on a recursive CSV import (and bulk create), a table's FK relationship to its referenced table disappeared even though the tableConstraints JSON was preserved. The single-entity path is unaffected (storeEntity -> addConstraintRelationship), which is why non-recursive imports kept the edge. Fix: after the bulk CONTAINS insert, re-add the constraint RELATED_TO edges via addConstraintRelationship, mirroring the single-entity store path. Test: DatabaseServiceResourceIT#test_importExportRecursive_preservesTableConstraints now also asserts the RELATED_TO edge survives a recursive round trip (read from the DAO, not the eventually-consistent search endpoint). Verified before/after on a live stack: without the fix the edge is dropped, with the fix it survives. (cherry picked from commit 25880b2) * perf(csv): batch FK edge restore; skip unresolved cross-chunk targets Addresses two review points on the initial fix: - N+1: the per-table addConstraintRelationship() did a getEntityReferenceByName lookup and a single addRelationship insert per foreign key. Replaced with buildConstraintRelationships(), which resolves all referred tables in one findByNames() query and folds the RELATED_TO edges into the caller's existing bulkInsertRelationships() call -- no per-FK query or insert. - Cross-chunk forward reference (greptile P1): addConstraintRelationship() resolved the referred table eagerly and threw EntityNotFoundException when the target was created later in another bulk chunk, failing the source table with BAD_REQUEST. The batched resolver skips a referred table that is not yet persisted instead of throwing, so a forward reference cannot fail the request. The edge is best-effort in the bulk path and is created whenever the target already exists -- always true for a recursive re-import of existing tables, the case that regressed. Duplicate edges are harmless (bulkInsertTo is INSERT IGNORE / ON CONFLICT DO NOTHING). Re-verified: recursive-import edge IT still GREEN, and live before/after confirms the FK edge survives a recursive import. (cherry picked from commit 4482fac) * perf(csv): resolve FK targets from the import batch before querying Referred tables already in the batch (the common recursive-import case) are resolved from memory, so only out-of-batch targets hit findByNames. Also walks constraints once and dedupes composite-FK targets per table. (cherry picked from commit 23bf8e2)
Problem
On a recursive CSV import (the whole-tree path the UI uses when importing at service/database/schema level), a table's foreign-key relationship edge (the
RELATED_TO/ ER graph link between the two tables) was dropped — even though thetableConstraintsJSON on the table was preserved.This was flagged by greptile on #31863 (and its backport #32095). It's a pre-existing issue, not introduced by #31863: before that PR the recursive path dropped both the JSON and the edge; #31863 restored the JSON, leaving the edge drop exposed.
Root cause
The bulk relationship path for tables is asymmetric:
clearEntitySpecificRelationshipsForManydeletes both the schemaCONTAINSedge and the FKRELATED_TOedge.storeEntitySpecificRelationshipsForManyre-added onlyCONTAINS.The single-entity path is fine (
storeEntity→addConstraintRelationship), which is why non-recursive imports (they re-PUT each table through the single path) keep the edge — only the recursive/bulk path drops it.Fix
After the bulk
CONTAINSinsert, re-add the constraintRELATED_TOedges viaaddConstraintRelationship, mirroring the single-entity store path. (addConstraintRelationshiponly acts on constraints withreferredColumns, i.e. foreign keys; PK/UNIQUE are no-ops.)Test
DatabaseServiceResourceIT#test_importExportRecursive_preservesTableConstraintsnow also asserts theRELATED_TOedge survives a recursive round trip, reading it from the relationship DAO (deterministic — the search-backed ER endpoint is eventually consistent). GREEN with the fix (Tests run: 1, Failures: 0).Also verified before/after on a live stack (direct
entity_relationshipquery): without the fix the FK edge is dropped by a recursive import; with the fix it survives, while thetableConstraintsJSON is preserved in both cases.Scope
Separate from the CSV constraint/custom-property PRs (#31863 and its backports #32095 / #32096) — this addresses only the ER relationship-edge gap greptile flagged. Backports to 1.13 / 2.0 to follow once this merges.
Greptile Summary
This PR restores table foreign-key
RELATED_TOedges during recursive and bulk relationship reconstruction.Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
RELATED_TOrelationships in the bulk table relationship-storage path using batched target resolution and insertion.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Recursive CSV import] --> B[Persist table entities] B --> C[Clear table-specific relationships] C --> D[Rebuild schema CONTAINS edges] C --> E[Resolve FK target table FQNs] E --> F[Build RELATED_TO edges] D --> G[Bulk insert relationships] F --> G G --> H[Persisted table relationship graph]Reviews (2): Last reviewed commit: "perf(csv): batch FK edge restore; skip u..." | Re-trigger Greptile
Context used:
Summary by Gitar
FQNsRELATED_TOedges into the singlebulkInsertRelationshipscallThis will update automatically on new commits.