Skip to content

Fixes 38939: Resolve stored parent references on read for every entity - #38950

Merged
yan-3005 merged 9 commits into
open-metadata:mainfrom
dk-teknologisk-rfma:fix/38939-stale-parent-display-name
Dec 3, 2026
Merged

yan-3005 merged 9 commits into
open-metadata:mainfrom
dk-teknologisk-rfma:fix/38939-stale-parent-display-name

Conversation

@dk-teknologisk-rfma

@dk-teknologisk-rfma dk-teknologisk-rfma commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #38939

Entities that keep a copy of their parent's reference in their own JSON now return the parent's current name, displayName and description, because that copy is never refreshed when the parent changes. This started with tables and database schemas (#38939) and now covers every entity with the same pattern.

Root cause. TableRepository.getFieldsStrippedFromStorageJson() strips only service, so table_entity.json keeps the full databaseSchema and database references. DatabaseSchemaRepository likewise keeps database. Both read paths trust those copies whenever they carry an id:

  • TableRepository.setDefaultFields (the "table JSON already stores database ref" fast path) returns early on hasId(...), and the bulk fetchAndSetDefaultFields keeps table.getDatabaseSchema() / table.getDatabase() as they are.
  • DatabaseSchemaRepository.setDefaultFields only calls getContainer when the database id is missing.

When the database's displayName changes, nothing rewrites the children's rows. Search propagation (getSearchPropagationDescriptors(), FIELD_DISPLAY_NAME as NESTED_FIELD) patches the child documents at that moment, so search looks right. But a full reindex reads entities through PaginatedEntitiesSource.readNextKeyset → listAfterKeyset → setFieldsInBulk, which returns the stale stored copies, and the index goes back to the old name. In Explore → Browse Estate (grouped by database.displayName) the renamed database then shows up twice.

Fix. Re-read the stored parent references on read, by id:

  • EntityRepository.currentReference(ref): single-entity path, via Entity.getEntityReferenceById (served from CACHE_WITH_ID, which is evicted on the parent's update).
  • EntityRepository.refreshStoredReferences(entities, parentType, getter, setter): bulk path. One findReferencesByIds query per parent type per page (distinct ids, reference columns only, no JSON deserialisation). A parent that can't be found keeps its stored copy.
  • TableRepository.setFields / setFieldsInBulk refresh databaseSchema and database. DatabaseSchemaRepository.setFields refreshes database; its bulk path already re-resolves database from relationships.

GET, list and the reindex all return the current labels, so a reindex no longer brings the old name back. Rows that are already stale are corrected on read, so no migration or reindex is needed.

Extended to every entity with a stored parent reference (85e6151). The same stale copy was returned by:

Entity Stored parent reference Stale before on
File directory, service list and reindex (the default setFieldsInBulk never calls setFields)
Query service GET and list
DataContract entity (any entity type), testSuite GET and list
Ontology definitions (concept, property, axiom, release) ontology GET and list
OntologyChangeSet ontology GET and list
AIFrameworkControl framework GET and list

Each repository now declares those references in getStoredParentReferences(). EntityRepository refreshes them after setFields on the single-entity path and at the start of the default setFieldsInBulk; Table, DatabaseSchema and Query, which override the bulk method, call refreshStoredParentReferences (Query through super). Table and DatabaseSchema moved onto the same declaration. refreshStoredReferences now groups ids by the type each stored reference names, so a field that can point at several entity types (a data contract's entity) costs one query per type.

Type of change:

  • Bug fix

High-level design:

Alternatives considered

  1. Rewrite children's stored refs when a parent's displayName/description changes (cascade on write). The read path stays free, but a rename of a database with N schemas and M tables becomes an O(N+M) JSON rewrite inside the PATCH (or a background job with its own failure handling). It also misses the rows that are already stale today, so it would need a migration as well. There is no existing rename-cascade for display names to hook into, and it would have to be repeated for every parent type. Rejected: more code and a slow, fragile write path for an edit users expect to be instant.
  2. Strip database/databaseSchema from storage JSON (as service already is) and always resolve through entity_relationship. That reverses the deliberate fast path (getContainer per table on GET, relationship joins in bulk), and it needs a migration to clean existing rows. Rejected: it costs more per read than (3) and changes the storage format.
  3. Re-read the refs by id on read (this PR). Single GET: two cached reference lookups for a table and one for a schema. List and reindex: two indexed IN (…) primary-key lookups per page, for tables, over the distinct parent ids (usually 1–2 rows), with no full-entity deserialisation. That is a small constant per page and never per entity. Measured below: no reindex regression, and zero extra SQL on GET.

Scope. Every entity that keeps a parent reference in stored JSON and returned it as stored: Table, DatabaseSchema, File, Query, DataContract, ontology definitions, OntologyChangeSet and AIFrameworkControl. A new entity with a stored parent reference declares it in getStoredParentReferences(). StoredProcedure re-resolves its schema on read, so it also gets the schema's fresh database. ADR:2026-11-27-stored-parent-references-are-resolved-on-read (v2) records the rule.

Compatibility. No schema, API or storage change.

Tests:

Use cases covered

  • After a database's displayName changes, GET /v1/tables/{id} returns the new database.displayName.

  • After a schema's displayName changes, GET /v1/tables/{id} returns the new databaseSchema.displayName.

  • GET /v1/databaseSchemas/{id} returns the database's new displayName.

  • GET /v1/tables?databaseSchema=… (the setFieldsInBulk path that the search reindex also reads through) returns the new database and schema display names, and so does GET /v1/databaseSchemas?database=….

  • After a drive service and directory are renamed, a file's service and directory are current on GET, list and in file_search_index after a full reindex.

  • After a database service, table, ontology or AI governance framework is renamed, the query's service, the data contract's entity, the ontology concept's and change set's ontology, and the AI control's framework are current on GET and list.

Unit tests

  • EntityRepositoryCurrentReferenceTest: found parent, missing parent keeps its stored copy, a field pointing at two entity types is refreshed with one query per type, and references without an id or type are left alone. Tests run: 5, Failures: 0, Errors: 0.

Backend integration tests

  • Added DatabaseHierarchyIT#childrenShowRenamedParentDisplayNames (openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DatabaseHierarchyIT.java).
  • Added StoredParentReferenceIT (one test per entity: File, Query, DataContract, OntologyConcept, OntologyChangeSet, AIFrameworkControl). On the code before this PR all 6 fail; with it, all 6 pass (mysql-elasticsearch, parallel lane):
before: [ERROR] Tests run: 8, Failures: 7, Errors: 0, Skipped: 0   (StoredParentReferenceIT 6/6, DatabaseHierarchyIT 1/2)
after:  [INFO]  Tests run: 8, Failures: 0, Errors: 0, Skipped: 0
  • Regression on the read paths this changes (mysql-elasticsearch, parallel lane): TableResourceIT 363, DatabaseSchemaResourceIT 234, FileResourceIT 222, QueryResourceIT 235, DataContractResourceIT 444, OntologyConceptResourceIT 209, OntologyChangeSetIT 12, AIFrameworkControlResourceIT 2, DatabaseHierarchyIT 2: Tests run: 1723, Failures: 0, Errors: 0, Skipped: 139.
  • The same 10 classes on postgres-opensearch (parallel lane), including StoredParentReferenceIT 6/6: Tests run: 1729, Failures: 0, Errors: 0, Skipped: 139, BUILD SUCCESS.

Scale and cost, measured on the same data with the code before this PR and with it:

Measurement Before After
ReindexBenchmarkIT (10k tables × 5 columns, scale-it profile), average of 2 measured reindexes, two runs each 47.0 s, 28.2 s 35.4 s, 32.3 s
SQL statements, 10 × GET /tables/{fqn} (warm cache) 82 82
SQL statements, 10 × GET /queries/{fqn} 10 10
SQL statements, 10 × list of 100 tables spread over 100 schemas 207 216
SQL statements, 10 × list of 100 schemas 150 174

The reindex numbers vary more between two runs of the same code than between the two versions. GET runs the same SQL (parents come from the entity cache); a list page adds one reference-only IN (…) query per parent type.

Fails on main (before the fix):

[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0 -- in org.openmetadata.it.tests.DatabaseHierarchyIT
org.opentest4j.AssertionFailedError: expected: <renamedDatabase__…__childrenShowRenamedParentDisplayNames> but was: <db__…__childrenShowRenamedParentDisplayNames>

Passes with the fix:

[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 -- in org.openmetadata.it.tests.DatabaseHierarchyIT
[INFO] BUILD SUCCESS

Run with the planner's focused command (mysql-elasticsearch, parallel lane):
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=DatabaseHierarchyIT …

Also run locally with the fix, as regressions on the changed read paths:

  • ITs (mysql-elasticsearch, parallel lane): TableResourceIT, DatabaseSchemaResourceIT, DatabaseResourceIT, DatabaseHierarchyIT, giving Tests run: 823, Failures: 0, Errors: 0, Skipped: 39, BUILD SUCCESS.
  • Unit tests in openmetadata-service: N1QueryFixValidationTest, EntityRelationshipPerformanceTest, InheritTagsTest, EntityRepositoryBulkFieldsTest, EntityRepositoryInheritanceParentTest, SearchIndexFactoryTest, giving Tests run: 325, Failures: 0, Errors: 0.
  • mvn spotless:check -pl openmetadata-service,openmetadata-integration-tests passes.

Not run locally: the full IT suite that the planner selects for an EntityRepository change (it runs in the merge queue), and the nightly ReindexBenchmarkIT / reindex UIITs.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Local server (MySQL 8.4, Elasticsearch 9.3), one database with 100 schemas plus a file, query, data contract, ontology concept and AI control. Every parent was renamed on the code before this PR, then the same database was read by that code and by this branch:

Read Before this PR With this PR
Table GET / list database old name current
File list directory, service old name current
Query GET / list service old name current
DataContract GET entity old name current
OntologyConcept GET / list ontology old name current
AIFrameworkControl GET framework old name current
After a full reindex: table_search_index database, file_search_index directory/service old name current

Rows written by the old code read correctly on this branch, so no migration is needed.

UI screen recording:

Not applicable: backend-only bug fix.

Checklist:

  • I have read CONTRIBUTING.md (the pre-review gate) and the contributor docs.

  • My PR title is Fixes <issue-number>: <short explanation>

  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.

  • I have commented on my code, particularly in hard-to-understand areas.

  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed. (No schema change.)

  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable).

  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.

  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). This description is gone from git log after the squash-merge.

  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

…schemas

Tables keep databaseSchema and database refs, and schemas keep their
database ref, in their stored JSON. Reads trusted those copies whenever
they had an id, so after a parent's displayName changed, GET, list and a
full search reindex (which reads through setFieldsInBulk) kept returning
the old name. Re-read the refs by id on read: a cached lookup on the
single-entity path, one batched reference query per page on the bulk path.

Fixes open-metadata#38939
@dk-teknologisk-rfma
dk-teknologisk-rfma requested a review from a team as a code owner November 27, 2026 08:59
@dk-teknologisk-rfma
dk-teknologisk-rfma requested review from manerow and a balanced review from Copilot November 27, 2026 08:59
@github-actions

github-actions Bot commented Nov 27, 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.

🟢 Approval recommended

No active review issues were identified for the parent-reference refresh change.

No open issues 🎉

What changed in this PR

Fixes #38939 by resolving current parent references when tables and database schemas are read, preventing stale parent labels from returning to search after a full reindex.

Changes:

  • Adds shared helpers for single-reference and batched parent-reference refreshes.
  • Refreshes table database/schema references and schema database references without changing storage or API contracts.
  • Adds integration coverage for updated parent display names in GET and list responses.

Placement: Covers backend reads used by API clients and search reindexing. End-to-end reindex performance and Collate behavior were not independently verified.

Trade-off: weighed by the author, holds because bulk refreshes use distinct parent IDs in two batched lookups per table page rather than per-table queries or cascading child-row rewrites. Throughput remains unbenchmarked.

Recommendation: Approve; no blocking issues were identified in the supplied review.

File Description
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​jdbi3/​TableRepository.java Refreshes database and schema references on single and bulk reads.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​jdbi3/​EntityRepository.java Adds reusable single and batched reference-refresh helpers.
openmetadata-service/​src/​main/​java/​org/​openmetadata/​service/​jdbi3/​DatabaseSchemaRepository.java Refreshes the database reference on single-schema reads.
openmetadata-integration-tests/​src/​test/​java/​org/​openmetadata/​it/​tests/​DatabaseHierarchyIT.java Tests current parent display names in GET and list responses.

Review effort: Balanced

currentReference threw EntityNotFoundException for a missing parent,
so a table or schema whose parent row was gone could no longer be read.
Fall back to the stored copy, as the bulk path already does, and record
the read-time resolution rule as a decision.
Copilot AI balanced review requested due to automatic review settings November 27, 2026 09:33

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.

🟢 Approval recommended

No active review issues are recorded, though tests were not rerun during review and integration checks remain pending.

No open issues 🎉

Review effort: Balanced

@yan-3005 yan-3005 added safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch labels Dec 1, 2026
@yan-3005

yan-3005 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@dk-teknologisk-rfma thanks, the fix works. I verified it on a local server (MySQL 8.4 + Elasticsearch 9.3) on one database:

  • Without the PR, after renaming the database and schema, GET /tables/{fqn} and GET /tables?databaseSchema=… returned the old database/databaseSchema display names, GET /databaseSchemas/{fqn} returned the old database name, and a full reindex put the old database name back into the table's search document.
  • With the PR, on the same rows (no migration), all of those return the current names, including the search document after a full reindex.
  • On the open Gitar thread: without the PR, GET /databaseSchemas?database=… already returned the current name, so the schema bulk path is fine as you said.

Cost, measured on the same data, warm cache, fixed vs unfixed (median / p95):

Call Without PR With PR
GET one table (300 calls) 6.5 / 9.6 ms 6.8 / 12.0 ms
List 100 tables (60 calls) 9.8 / 14.0 ms 9.7 / 14.2 ms
List 100 tables with owners, tags, columns (60 calls) 17.7 / 32.4 ms 17.1 / 28.6 ms

Request 1: apply the rule to every entity with the same pattern, in this PR. The ADR states the rule generally, but these entities still return a stale parent copy:

Entity Stored parent copy Stale on
File directory, service list and reindex. FileRepository has no setFieldsInBulk override, and the default EntityRepository.setFieldsInBulk never calls setFields
Query service GET and list. QueryRepository.setFields doesn't touch it, and the bulk path only fills queries where it is null
DataContract entity GET and list. setFields is empty; the reference is stored at create
Ontology definitions (OntologyEntityRepository) ontology GET and list. Stored in prepare, not stripped, not re-read in setFields
AIFrameworkControl framework GET and list. setFields is empty

Rather than patching each repository by hand, could each repository declare the parent references it keeps in stored JSON (for example a getStoredParentReferences() hook), and have EntityRepository refresh them with currentReference / refreshStoredReferences in both the single and the bulk read paths? Table and DatabaseSchema would then use the same hook, and a new entity gets the behaviour by declaring its fields. Please add an IT per entity that renames the parent and checks GET, list and, for indexed entities, the search document after a reindex.

Request 2: run a scale benchmark, before and after. Please run ReindexBenchmarkIT (10k tables, @Tag("scale"), run through the scale-it profile like the nightly job) on main and on this branch, and post the throughput from target/benchmark/reindex-benchmark.json for both. Please also time a table list page whose 100 tables come from many different schemas. My numbers above only cover one database and two schemas, so the parent lookups were always cache hits.

Also needed before merge: issue #38939 has to be added to the Shipping project for Validate PR Metadata.

Tables and schemas were not the only entities returning a renamed parent's
old displayName. File (directory, service on list and reindex), Query
(service), DataContract (entity, testSuite), ontology definitions and
OntologyChangeSet (ontology) and AIFrameworkControl (framework) all keep a
copy of their parent reference in stored JSON and returned it as stored.

Each repository now declares those references in
getStoredParentReferences(). EntityRepository refreshes them after setFields
on the single-entity path (entity cache) and at the start of the default
setFieldsInBulk (one reference-only query per parent type per page). Table
and DatabaseSchema move onto the same declaration. refreshStoredReferences
groups ids by the type each reference names, so a field that points at
several entity types costs one query per type.

StoredParentReferenceIT renames each parent and checks GET and list for
every declared entity; it fails on the code before this PR.
Copilot AI balanced review requested due to automatic review settings December 2, 2026 06:48
@yan-3005 yan-3005 changed the title Fixes 38939: Resolve stored parent references on read for tables and schemas Fixes 38939: Resolve stored parent references on read for every entity Dec 2, 2026
@yan-3005

yan-3005 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@dk-teknologisk-rfma I pushed 85e6151 on top of your two commits, so the fix covers every entity that keeps a parent reference in its stored JSON, not only tables and schemas.

  • Each repository declares those references in getStoredParentReferences(), and EntityRepository refreshes them with your currentReference / refreshStoredReferences helpers on both the single and the bulk read path. Table and DatabaseSchema use the same declaration now.
  • Newly covered: File (directory, service), Query (service), DataContract (entity, testSuite), ontology definitions and OntologyChangeSet (ontology), AIFrameworkControl (framework).
  • StoredParentReferenceIT renames each parent and checks GET and list; all 6 tests fail on the code before this PR and pass with it. The ADR is updated to v2.
  • Measured: no ReindexBenchmarkIT regression (10k tables), identical SQL on GET, and one reference-only query per parent type per list page. Details and the live-server check are in the description.

This replaces the two requests in my previous comment, so there is nothing left for you to do there.

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.

🟡 Changes recommended

No-op contract updates can trigger spurious change events and version increments, while incomplete integration-test cleanup leaves fixtures in shared catalogs.

2 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 2, 2026 11:39

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.

🟢 Approval recommended

No active review issues were identified for the changes intended to prevent stale parent labels in API responses and rebuilt search indexes.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@sonika-shah

Copy link
Copy Markdown
Collaborator

I benchmarked this against main to check the read-path cost. Table and schema reads are fine. Data contract reads get slower when the contract's table is wide.

Request main median / p95 PR median / p95 SQL per request, main → PR
GET /dataContracts/{id}, contract on a 1,200-column table 2.7 / 4.4 ms 4.0 / 6.5 ms (+48%) 1 → 1
GET /dataContracts/{id}, contract on a 10-column table (2 rounds) 2.6 / 3.4 ms 2.3 / 4.2 ms 1 → 1
GET /dataContracts?limit=100 (50 wide-table contracts) 4.6 / 6.1 ms 7.2 / 9.7 ms (+57%) 2 → 3
GET /tables?limit=1000 108.2 / 158.6 ms 108.6 / 136.5 ms +2 per page
GET /databaseSchemas?limit=1000 22.6 / 35.0 ms 21.6 / 28.9 ms +1 per page (DatabaseDAO.findReferencesByIds now runs twice)
GET /tables/{id} 6.8 / 9.0 ms 6.8 / 8.9 ms no change
Reindex of table + databaseSchema (6,350 docs) 34.2–37.4 s 33.9–36.0 s n/a

Setup: MySQL 8.4 and Elasticsearch 9.3 running locally. Synthetic data: 300 schemas, 6,000 tables with 10 columns each, and 50 tables with 1,200 columns each (about 585 KB of stored JSON per table), each of those with a data contract. Both builds ran on the same database, port and JVM settings, taking turns over 5 runs each, with the cache warm.

The data contract slowdown showed up in every run. Per-run medians for the single GET were 2.3–3.2 ms on main and 3.6–4.9 ms on the PR. For the list they were 4.2–5.0 ms on main and 6.9–7.6 ms on the PR.

  • Single GET: no extra SQL. The added ~1.3 ms is spent rebuilding the entity reference by deserializing the whole table JSON from the entity cache. A contract on a 10-column table shows no difference.
  • List: one extra TableDAO.findReferencesByIds per page. On MySQL its JSON_EXTRACT still reads each wide table's full JSON: 2.2 ms for 50 wide rows vs 0.9 ms for 50 narrow rows, timed directly in MySQL.

The absolute numbers are small at this size, but they grow with the number of columns.

Ask: resolve the contract's entity with the reference-only lookup instead of find() (my inline comment on currentReference). Run directly in MySQL, that query took 0.4 ms for one wide row; I haven't measured it end to end. The duplicate query on the schema list (DatabaseSchemaRepository.java:238) and the schema-reference query on the table list (TableRepository.java:246), both covered by my inline comments, made no measurable latency difference here. They are still one extra round trip per page each, so I'd still drop them.

- A data contract's entity (usually a table) is read with the reference-only
  query on the single-entity path: rebuilding the reference from the entity
  cache deserialized the whole table JSON on every GET.
- A contract's testSuite is no longer declared: the contract owns its suite.
  This also restores the plain testSuite comparison in the updater.
- The schema list no longer runs a second database query: every stored row
  already goes through batchFetchDatabases.
- The table list takes databaseSchema from the schemas fetchAndSetDefaultFields
  already loaded, so only the database reference needs a query.
- StoredParentReferenceCoverageTest fails when a repository with stored parent
  references overrides setFieldsInBulk without being listed with its test.
- The decision record lists the covered entities and the stored references not
  declared yet.
Copilot AI balanced review requested due to automatic review settings December 2, 2026 18:50

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.

🔵 Needs a closer look

Human assessment is needed because global entity-registry cleanup can erase concurrent tests’ fixtures and cause intermittent failures.

No open issues 🎉

Review effort: Balanced

AIFrameworkControl (`framework`). A new entity that keeps a parent reference in stored JSON
declares it instead of cascading on write. A contract's `testSuite` is not declared: the contract owns
its suite rather than living under it. The rule covers the entities listed here; stored references
not declared yet include `TestSuite.basicEntityReference`, `AuditReport.framework`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since each repository has to opt in, a new entity that keeps a parent ref in its stored JSON and forgets to declare it gets stale parent names silently. This list already has four of them. StoredParentReferenceCoverageTest only looks at repositories that already declare something. Could we add a test that, for every entity type, finds the single EntityReference fields that survive storage (storage strips only the known list plus getFieldsStrippedFromStorageJson()) and fails unless each one is declared in getStoredParentReferences() or on a skip list with a reason (e.g. the contract's testSuite)? It stays explicit, but forgetting one fails CI. Fine as a follow-up if you prefer.

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.

Done in this PR (c3802c9): StoredReferenceDeclarationTest walks every concrete repository, finds the single EntityReference fields its entity keeps in stored JSON (after FIELDS_STORED_AS_RELATIONSHIPS and getFieldsStrippedFromStorageJson()), and fails unless each is declared in getStoredParentReferences() or listed with a reason. 64 are listed today, grouped as: re-read by their own repository (verified), actors, configuration links, deprecated single domain, owned or point-in-time (incl. the contract's testSuite), and two parents not declared yet (ContextFileContent.contextFile, PromptTemplate.parentTemplate). A second test fails if a listed field stops being stored or gets declared, so the list can't go stale.

overrides the bulk method keeps its references current on that path, and
`StoredParentReferenceCoverageTest` lists each such repository with the test that covers it.

## Consequences

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: a couple of side effects worth listing here:

  • storeEntityHistory stores the refreshed original, so a previous version now shows the parent's label at update time rather than the stale copy (arguably better, but a change).
  • Reads that don't go through setFieldsInternal / setFieldsInBulk still return the stored copy: /versions/{v}, raw dao.find* reads, and search-backed lists until propagation or a reindex.

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.

Added to the record's consequences in c3802c9: version history now holds the refreshed parent labels, and /versions/{v}, raw dao.find* reads and search-backed lists (until propagation or a reindex) still return the stored copy.

if (storedReference != null && storedReference.getId() != null) {
try {
current =
Entity.getEntityReferenceById(storedReference.getType(), storedReference.getId(), ALL);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: with ALL, a child under a soft-deleted parent now returns deleted: true on that ref. That's consistent with cascade soft-delete, but API clients will see it, so maybe mention it in the ADR.

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.

Added to the record in c3802c9: with Include.ALL, a child under a soft-deleted parent returns deleted: true on that reference. StoredParentReferenceIT#softDeletedParentIsReportedOnTheChildReference now covers it (fails on main).

try {
current =
Entity.getEntityReferenceById(storedReference.getType(), storedReference.getId(), ALL);
} catch (EntityNotFoundException e) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: when the parent was hard-deleted, this throws on every read of the orphaned child. As far as I can see the not-found cache is only populated for NON_DELETED lookups, so each read goes to the DB. It only affects orphans, so not a blocker, but worth knowing.

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.

Right, it only affects orphans, so I left the behaviour and wrote it down in the record (c3802c9): the orphan keeps its stored copy and each read looks the parent up again, since the not-found cache only covers NON_DELETED.

final Map<UUID, EntityReference> currentById = new HashMap<>();
parentIdsByType.forEach(
(type, ids) ->
Entity.getEntityReferencesByIds(type, List.copyOf(ids), ALL)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: this assumes every stored type has a repository. Today it holds because the declared types are validated on write, but if a pseudo-type ever ends up here (like the tableColumn refs that broke list endpoints before), the whole page fails. Skipping types where !Entity.hasEntityRepository(type) would keep it safe.

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.

Done in c3802c9: a reference whose type has no repository (!Entity.hasEntityRepository(type)) is not resolvable, so it keeps its stored copy on both paths instead of failing the read or the page.


table.withDatabaseSchema(schemaRef).withDatabase(databaseRef).withService(serviceRef);
table
.withDatabaseSchema(schema.getEntityReference())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: this refreshes databaseSchema only for rows that go through the missing-defaults path. That's every row today because service is always stripped, but if a stored row ever had all defaults, its schema ref would go stale again without anyone noticing. A short comment (or an assertion in the test) tying the two together would help.

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.

Added a comment in c3802c9 tying it to service being stripped (so hasDefaultFields is false for every stored row), and StoredParentReferenceCoverageTest names this path for TableRepository with DatabaseHierarchyIT as its test.


@Test
void dataContractShowsRenamedEntity(TestNamespace ns) {
// The contract's testSuite is declared too, but renaming a suite writes a string into the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: this comment still says the contract's testSuite is declared, but it was dropped in 829638b.

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.

Removed in c3802c9.

@Test
void dataContractUpdateWithoutChangesKeepsItsVersion(TestNamespace ns) {
// Reads return the suite's current reference while prepare() rebuilds it from id, FQN and type,
// so an unchanged PUT must compare the suite by identity, not record it as changed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: same here. The suite isn't declared any more, so this test now also passes on main and doesn't guard anything this PR changes. Update the comment, or drop the test?

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.

Agreed, it no longer guarded anything this PR changes, so I dropped it (and its test-case helper) in c3802c9.

private static final String AI_GOVERNANCE_FRAMEWORKS = "/v1/aiGovernanceFrameworks";

@Test
void fileShowsRenamedDirectoryAndService(TestNamespace ns) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: a few cases aren't covered yet. A reindex of a table under a renamed schema/database (the bug in the issue, currently only checked manually), a PATCH on a child after its parent is renamed (should be a no-op diff, no version bump), and a soft-deleted parent at IT level. Even one reindex assertion would be useful.

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.

Added all three in c3802c9: tableSearchDocShowsRenamedParentsAfterReindex (deletes the table's doc, reindexes it through /v1/search/reindexEntities, asserts the renamed database and schema in the doc), tableUpdateWithoutChangesAfterParentRenameKeepsItsVersion, and softDeletedParentIsReportedOnTheChildReference. On main's production code the reindex and soft-delete tests fail along with the existing per-entity ones (9 of 10); on this branch all 9 StoredParentReferenceIT tests pass.

- StoredReferenceDeclarationTest finds, for every repository, the single
  EntityReference fields its entity keeps in stored JSON and fails unless each
  is declared in getStoredParentReferences() or listed with its reason. The
  64 listed today are grouped: re-read by their own repository, actors,
  configuration links, deprecated single domains, owned or point-in-time
  references, and two parents not declared yet.
- A stored reference whose type has no repository keeps its stored copy
  instead of failing the read.
- StoredParentReferenceIT covers the reindexed search doc of a table under
  renamed parents, an unchanged update after a parent rename and a
  soft-deleted parent; the no-op contract PUT test no longer guarded this
  change and is dropped.
- The decision record lists the side effects: deleted on references under a
  soft-deleted parent, refreshed labels in version history, orphan lookups,
  and the reads that still return the stored copy.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 06:10

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.

🟢 Approval recommended

The supplied review reports no active issues requiring changes.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 3, 2026 06:15

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.

🟢 Approval recommended

No active review issues were identified, though reported tests were not rerun and cross-repository behavior was not independently verified.

No open issues 🎉

Review effort: Balanced

@gitar-bot

gitar-bot Bot commented Dec 3, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 3 closed / 3 findings

Refreshing stored parent references across GET, list, and reindex paths changes returned metadata, so clients may see updated labels and deleted status.

Stored parent references on tables, schemas, files, queries, data contracts, ontology definitions and AI framework controls are now re-read by id on every read, so GET, list and full reindex return current parent names instead of stale copies. Review found no open issues. Resolved this session: single-entity reads no longer throw when a stored parent is missing, the read-time resolution rule is now recorded in docs/decisions, and the schema list/reindex path refreshes the stored database reference.

✅ 3 closed
✅ Bug: Single-entity read throws when stored parent is missing

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java:7154-7158 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java:213-215 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseSchemaRepository.java:175
The description says a parent that cannot be found keeps its stored copy. The bulk helper does this through getOrDefault. currentReference, however, calls Entity.getEntityReferenceById, which goes to repository.getReference → find(id, include), and that throws EntityNotFoundException when the id is gone. A table or schema whose stored parent row is missing (an orphan row, or a parent hard-deleted mid-cascade) used to load with its stored ref. Now GET by id/name fails, and so does any internal setFields caller such as the update/patch paths. The single path and the bulk path also behave differently. To fix it, catch EntityNotFoundException and fall back to the stored reference, or route the single path through the same getEntityReferencesByIds lookup.

✅ Quality: Read-time parent-ref resolution rule is not recorded in docs/decisions

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java:7149-7163
This PR makes a cross-cutting rule that other entities are expected to follow later. The description says "File.service/directory and DataContract.entity ... may follow", and it also rejects two alternatives: cascading renames on write, and stripping refs from storage JSON. No record in docs/decisions/ states this rule, and the repo squash-merges, so the reasoning would be lost. The record should say: "A parent reference kept in a child's stored JSON is re-resolved by id on every read (single and bulk, one reference-only query per parent type per page); a parent that cannot be found keeps its stored copy; parent renames are not cascaded onto child rows on write." Add that record in this PR, and cite it from currentReference.

✅ Bug: Schema list/reindex path never refreshes the stored database ref

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DatabaseSchemaRepository.java:175 📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DatabaseHierarchyIT.java:87-93
The fix only touches DatabaseSchemaRepository.setFields. Listing (listAfter/listBefore), get(ids), getByNames and the search reindex all go through setFieldsInBulk, and DatabaseSchemaRepository.setFieldsInBulk (lines 228-253) was not changed. So schemas still come back with their old database.displayName on list and reindex, which is the Browse Estate / reindex symptom from #38939. The new IT assertion at DatabaseHierarchyIT.java:87-93 on listedSchema.getDatabase().getDisplayName() should fail. To fix it, call refreshStoredReferences in the schema bulk path, after fetchAndSetDefaultFields, the same way TableRepository does.

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

@yan-3005
yan-3005 enabled auto-merge (squash) December 3, 2026 06:30
@yan-3005
yan-3005 merged commit c76ee35 into open-metadata:main Dec 3, 2026
17 of 18 checks passed
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.1 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

gh-bot-collate Bot commented Dec 3, 2026

Copy link
Copy Markdown

🤖 Backport to 2.1 opened as #39624 (clean cherry-pick). It merges itself once the checks pass.

@gh-bot-collate

gh-bot-collate Bot commented Dec 3, 2026

Copy link
Copy Markdown

🤖 Backport to 2.0 failed. The conflict could not be resolved, so this change is not on that branch. Resolver run.

sonika-shah pushed a commit that referenced this pull request Dec 3, 2026
#38950) (#39624)

* Fixes 38939: Resolve stored parent references on read for tables and schemas

Tables keep databaseSchema and database refs, and schemas keep their
database ref, in their stored JSON. Reads trusted those copies whenever
they had an id, so after a parent's displayName changed, GET, list and a
full search reindex (which reads through setFieldsInBulk) kept returning
the old name. Re-read the refs by id on read: a cached lookup on the
single-entity path, one batched reference query per page on the bulk path.

Fixes #38939

* Keep a stored parent reference when the parent is gone

currentReference threw EntityNotFoundException for a missing parent,
so a table or schema whose parent row was gone could no longer be read.
Fall back to the stored copy, as the bulk path already does, and record
the read-time resolution rule as a decision.

* Refresh every stored parent reference on read

Tables and schemas were not the only entities returning a renamed parent's
old displayName. File (directory, service on list and reindex), Query
(service), DataContract (entity, testSuite), ontology definitions and
OntologyChangeSet (ontology) and AIFrameworkControl (framework) all keep a
copy of their parent reference in stored JSON and returned it as stored.

Each repository now declares those references in
getStoredParentReferences(). EntityRepository refreshes them after setFields
on the single-entity path (entity cache) and at the start of the default
setFieldsInBulk (one reference-only query per parent type per page). Table
and DatabaseSchema move onto the same declaration. refreshStoredReferences
groups ids by the type each reference names, so a field that points at
several entity types costs one query per type.

StoredParentReferenceIT renames each parent and checks GET and list for
every declared entity; it fails on the code before this PR.

* Leave the test suite rename out of the shared-server data contract test

Renaming a contract's test suite writes a string into the embedded
testSuites change description of its test cases, which the shared data
insights index maps as boolean (#38799), so DataInsightAiAssetCoverageIT
rejected the record. The test keeps checking the contract's entity.

* Compare a data contract's test suite by identity

Reads now return the suite's current reference, while prepare() rebuilds
updated.testSuite from its id, FQN and type, so the full-object comparison
recorded a testSuite change on an unchanged PUT and bumped the version.
Compare it with entityReferenceMatch, as qualityExpectations already is.

StoredParentReferenceIT gains a no-op PUT test (0.1 -> 0.2 before this
change) and now cleans up its drive and database services, ontologies and
AI framework fixtures.

* Read large parents by reference row and drop redundant list queries

- A data contract's entity (usually a table) is read with the reference-only
  query on the single-entity path: rebuilding the reference from the entity
  cache deserialized the whole table JSON on every GET.
- A contract's testSuite is no longer declared: the contract owns its suite.
  This also restores the plain testSuite comparison in the updater.
- The schema list no longer runs a second database query: every stored row
  already goes through batchFetchDatabases.
- The table list takes databaseSchema from the schemas fetchAndSetDefaultFields
  already loaded, so only the database reference needs a query.
- StoredParentReferenceCoverageTest fails when a repository with stored parent
  references overrides setFieldsInBulk without being listed with its test.
- The decision record lists the covered entities and the stored references not
  declared yet.

* Require every stored reference to be declared or listed with a reason

- StoredReferenceDeclarationTest finds, for every repository, the single
  EntityReference fields its entity keeps in stored JSON and fails unless each
  is declared in getStoredParentReferences() or listed with its reason. The
  64 listed today are grouped: re-read by their own repository, actors,
  configuration links, deprecated single domains, owned or point-in-time
  references, and two parents not declared yet.
- A stored reference whose type has no repository keeps its stored copy
  instead of failing the read.
- StoredParentReferenceIT covers the reindexed search doc of a table under
  renamed parents, an unchanged update after a parent rename and a
  soft-deleted parent; the no-op contract PUT test no longer guarded this
  change and is dropped.
- The decision record lists the side effects: deleted on references under a
  soft-deleted parent, refreshed labels in version history, orphan lookups,
  and the reads that still return the stored copy.

---------



(cherry picked from commit c76ee35)

Co-authored-by: Rolf Malthe Andersen <[email protected]>
Co-authored-by: Ram Narayan Balaji <[email protected]>
Co-authored-by: Ram Narayan Balaji <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Children keep a stale parent displayName after the parent is renamed; a full reindex brings it back into search

4 participants