Skip to content

fix(migration): move Context Center file tags on upgrades where later tables do not exist yet - #37960

Merged
manerow merged 7 commits into
mainfrom
fix/context-file-fqn-repair-missing-tables
Nov 17, 2026
Merged

manerow merged 7 commits into
mainfrom
fix/context-file-fqn-repair-missing-tables

Conversation

@manerow

@manerow manerow commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

No linked issue yet: this is a follow-up to PR #37796, which had none either.

PR #37796 added the 2.1.0 data step repairContextFileFqns. It gives Context Center files that an edit stored under their bare name their folder path back, and moves the file's tags to that path. Before moving them, it checks every registered entity table for another entity with the bare name. If any of those lookups fails, it assumes another entity owns the name and leaves the tags where they are.

An upgrade runs each version's data step before later versions create their tables, while every entity type of the new build is already registered. On a server that registers types a later migration creates (Collate does, in its 2.1.0-collate folder, which runs after 2.1.0), those lookups always fail. So every repaired file kept its tags under the old name: the file showed no tags, the step recorded itself as done, and only a WARN line said so.

This PR:

  • Moves the lookup into a small helper, EntityFqnHolders, built once per run.
  • Treats a table as empty only when the database itself says it does not exist (SQLSTATE 42S02 on MySQL, 42P01 on Postgres). It then logs that once and does not query that table again. Any other failure still counts as "another entity may own this name", so the tags stay. That is the same safe behaviour as before.
  • Adds a FolderIT guard that a PATCH on a nested folder keeps its full name. I first suspected folders had the same bug as files. They don't: the base restorePatchAttributes restores the stored FQN, and ContextFileRepository was the one override that skipped it. The test keeps it that way.

The step name is unchanged. 2.1.0 has not shipped with this step, so only test databases can have run the broken version.

Type of change:

  • Bug fix

High-level design:

N/A, small change.

Tests:

Use cases covered

  • Upgrading a Collate 2.0.8 database to 2.1: damaged files get their folder path and keep their tags.
  • A table that exists but cannot be searched still keeps the file's tags in place.
  • A missing table is queried once per run, not once per file.
  • Patching a nested folder keeps its full name.

Unit tests

  • Not added. EntityFqnHolders only talks to the database, so it is tested against real MySQL and Postgres in EntityFqnHoldersIT instead of with mocks.

Backend integration tests

  • Added EntityFqnHoldersIT (4 tests) and FolderIT#testPatchingANestedFolderKeepsItsFullyQualifiedName.
  • Ran ContextFileFqnRepairMigrationIT as the regression for the repair step, together with EntityFqnHoldersIT and FolderIT, on both MySQL/Elasticsearch and Postgres/OpenSearch at 579e6b9a: all passed.
  • ContextFileFqnRepairMigrationIT cannot reproduce the Collate case itself, because OpenMetadata alone has every table. The upgrade run below covers it.

Local Java test run: PASSED

  • Commit: 2c2acf326228 (base origin/main)
  • Finished: 2026-11-17 09:42 UTC · 2.8 min
  • Scope: focused; merge readiness is not established. Broader steps deferred: 3 (run --scope full).
Step Scope Classes Tests Failed Skipped Min Result
integration mysql-elasticsearch · parallel 2 20 0 0 2.8 passed

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Visual regression baselines

  • Not applicable (no rendering change).

Manual testing performed

I ran a real Collate upgrade from 2.0.8, on Postgres and on MySQL, with and without this fix:

  1. Ran the released 2.0.8 server and created a root folder Reports, a nested folder Reports.Q3, a file in each, and one at the root, all tagged.
  2. Edited the files. 2.0.8 then stored them under their bare names, with the tags from the edit under the bare name too.
  3. Ran openmetadata-ops.sh migrate with a 2.1 Collate build that includes PR fix(security): access control hardening #37796:
    • Without this fix: the file names were repaired, the tags stayed under the bare names, and the log said governance_automation_entity and metadata_standard_entity were "not looked up".
    • With this fix: the tags moved to the folder path, the log said each of those tables "does not exist yet" once, and GET /v1/contextCenter/drive/files/name/{fqn}?fields=tags returned every tag.

UI screen recording:

Not applicable: backend migration fix.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation> (no issue, see above)
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above. (no issue, see 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: not applicable, backend only.
  • 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.
    • Reviewed 579e6b9a, with no 🔴 left. Fixed on the way:
      • an existence pre-check that read a failed check as "missing"
      • a Javadoc that no longer matched
      • re-querying a missing table for every file, now pinned by aTableFoundMissingIsNotLookedUpAgain, which fails with the cache removed
    • Answered without a code change:
      • repairAll has no test with a missing table. Adding one needs a production overload just for tests, so the Collate upgrade run covers it instead.
      • The FolderIT test is a guard, not a reproduction (see above).
    • Bot follow-ups in 2c2acf32: the decision record, List.copyOf returns and final locals. No behaviour change; the focused run above is on that commit.
  • Decision check: added docs/decisions/2026-11-17-a-migration-entity-lookup-treats-only-a-missing-table-as-empty.md, cited from EntityFqnHolders. The rule depends on the order in which migrations run, which no single file shows.
  • I have added a test that covers the exact scenario we are fixing.

RetriggerView in GreptileConfidence Score: 4/5

The Java guide's requirement to catch specific exceptions remains unmet and must be addressed before merging.

Findings

  1. P2 The catch is too broad ▶

Summary

The PR lets the file-name repair move tags when later migrations have not created every registered entity table.

  • Upgrades now move repaired file tags past tables created later.
  • Nested-folder PATCH tests now check that the folder keeps its full name.

Reviews (7) · Last reviewed commit: "docs(migration): record that a migration..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner November 17, 2026 08:58
@manerow
manerow requested a review from yan-3005 November 17, 2026 08:58
@manerow

manerow commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Local Java test run: PASSED — details

  • Commit: 579e6b9a11d9 (base origin/main)
  • The summary is in the PR description.

Tests run locally

  • integration · mysql-elasticsearch · parallel: EntityFqnHoldersIT (4 passed), FolderIT (16 passed)

Per-class counts come from the test reports, which can credit a test to the wrong class when classes run concurrently, and keep only the last run of a nested class that several test classes inherit. The summary's step totals are Maven's own counts.

Broader coverage not executed by this focused run

  • mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=IngestionPipelineMigrationEntryPointTest -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<35 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=ConversationSchemaMigrationIT,MetricMigrationIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Commands
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=EntityFqnHoldersIT,FolderIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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 skip-pr-checks label.

@manerow

manerow commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Local Java test run: PASSED — details

  • Commit: 2c2acf326228 (base origin/main)
  • The summary is in the PR description.

Tests run locally

  • integration · mysql-elasticsearch · parallel: EntityFqnHoldersIT (4 passed), FolderIT (16 passed)

Per-class counts come from the test reports, which can credit a test to the wrong class when classes run concurrently, and keep only the last run of a nested class that several test classes inherit. The summary's step totals are Maven's own counts.

Broader coverage not executed by this focused run

  • mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=IngestionPipelineMigrationEntryPointTest -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<35 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=ConversationSchemaMigrationIT,MetricMigrationIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Commands
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=EntityFqnHoldersIT,FolderIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

@gitar-bot

gitar-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk 1 closed / 1 findings

Changing the Context Center migration’s FQN-holder check lets tag rows move past absent tables; a mistaken absence could misassign stored tags.

Moves Context Center file tag repair to a per-run EntityFqnHolders lookup that treats only database-reported missing tables as empty, so tags move to the folder path on upgrades where later Collate tables do not exist yet. Resolved the missing decision record, now added at docs/decisions/2026-11-17-a-migration-entity-lookup-treats-only-a-missing-table-as-empty.md and cited from the EntityFqnHolders Javadoc. No open findings.

✅ 1 closed
✅ Quality: Missing-table-holds-nothing migration rule is not recorded in docs/decisions

📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/EntityFqnHolders.java:33-37 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/EntityFqnHolders.java:41-42 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/EntityFqnHolders.java:126-140 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/ContextFileFqnRepair.java:61-62 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/ContextFileFqnRepair.java:113-116
This PR adds a rule that depends on migration order across components: during a migration every entity type of the running build is registered, but tables from later migrations (for example Collate's 2.1.0-collate) may not exist yet. So a lookup that fails with SQLSTATE 42S02 (MySQL) or 42P01 (Postgres) means the table holds no entity, and any other failure counts as a holder, so the file's tags stay in place. The description says the step now "treats a table as empty only when the database reports it missing". No record in docs/decisions/ states this rule. Right now it exists only in Javadoc in a new shared utility (migration/utils/EntityFqnHolders), and later migrations that reuse it will depend on it.

Suggested record: "A data migration that looks entities up across every registered entity table treats a table as empty only when the database reports it missing (SQLSTATE 42S02 / 42P01); any other lookup failure counts as the name being taken, and a table found missing is not queried again in that run."

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

Comment on lines +121 to +122
} catch (Exception e) {
return missingTable(e) ? notCreatedYet(table) : notLookedUp(table, e);

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.

P2 The catch is too broad

holdingIn() catches Exception, which violates the Java guide's instruction to catch specific exception types. Catch the database query exception instead, while keeping the distinction between missing tables and other lookup failures. This repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@manerow
manerow merged commit a207ac4 into main Nov 17, 2026
66 of 70 checks passed
@manerow
manerow deleted the fix/context-file-fqn-repair-missing-tables branch November 17, 2026 10:09
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.

2 participants