Skip to content

Fixes #38346: check derived FQN across all entity tables before moving tags - #38383

Merged
yan-3005 merged 3 commits into
mainfrom
detail/bug-fix/fixes-38346-check-derived-fqn-across-all-entity-ta-118f03
Nov 23, 2026
Merged

yan-3005 merged 3 commits into
mainfrom
detail/bug-fix/fixes-38346-check-derived-fqn-across-all-entity-ta-118f03

Conversation

@detail-app

@detail-app detail-app Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Describe your changes:

Fixes #38346

I worked on the 2.1.0 ContextFileFqnRepair migration because its tag_usage collision guards were asymmetric and could silently merge one entity's tags onto another unrelated entity at upgrade time.

  • Bug: The migration repairs Context Center files whose stored FQN fell back to the bare file name (a released PATCH bug) by re-deriving the FQN from the folder and moving the file's tag_usage rows to the derived FQN's hash. Before moving, it scanned the stored FQN across every registered entity table (and skipped the move + logged if another entity owned it), but checked the derived FQN only against other context_file rows. When a non-file entity (a subfolder, glossary term, subdomain, … with FQN parentFQN + "." + name) already held the derived FQN, the migration moved the file's rows onto that hash anyway. tag_usage is keyed by FQN hash alone with no owner, so the two entities' rows merged: the co-tenant started displaying the file's tags (and the file the co-tenant's), and a tag they shared had the file's stored-side row deleted outright. The migration is runOnce, so this was never retried or re-evaluated.
  • Fix: Make the derived-side guard symmetric with the stored-side guard. repair(...) now runs EntityFqnHolders.holding(...) (the all-entity scan) for both the stored and the derived FQN, and moveTags runs only when both return no non-context_file holder. When a non-file entity holds the derived FQN, the file's FQN and nameHash are still repaired (the rename is safe — context_file.nameHash is unique per table), but the tag rows are left under the bare-name hash and the file, both FQNs, and the co-tenant are logged for hand repair — exactly as the stored-side branch already did. The entitiesSharing helper was generalized from (holders, misnamed) to (holders, fqn, id) and is called for both FQNs. The class javadoc was updated to describe the symmetric policy.

Type of change:

  • Bug fix

High-level design:

N/A — small change. The fix mirrors the migration's own stored-side collision policy onto the derived side, using the existing EntityFqnHolders all-entity scan that already runs for the stored FQN. No new tables, no schema change, no migration version bump — the runOnce step's logic is corrected.

Tests:

Use cases covered

  • A Context Center file damaged to its bare name, in a folder, where a subfolder under the same parent holds the derived FQN: the file's FQN/nameHash are repaired, the subfolder keeps only its own tags, no tag_usage row moves or is deleted (the new derived-side cross-type collision case from the bug report).
  • The same scenario with a glossary term (different entity type) holding the derived FQN: the term keeps only its own tags and no row moves onto its hash (guards against narrowing the scan to context_file + folder only).
  • Pre-existing cases unchanged: the stored-side cross-type collision (root folder / root glossary named like the bare name) still leaves rows in place; a file-vs-file derived-FQN collision still leaves the file as-is; the happy path still moves rows from the bare-name hash to the derived-FQN hash.

Unit tests

  • Not applicable — no unit-testable pure logic changed. ContextFileFqnRepair.repairAll is mocked at the v210 entry point (IngestionPipelineMigrationEntryPointTest); its public signature is unchanged and that test still passes (2/2). The repair behaviour is exercised by the integration tests below.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for the changed migration logic.
  • Files added/updated: openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/ContextFileFqnRepairMigrationIT.java (2 new tests: aSubfolderNamedLikeTheFileUnderTheSameParentKeepsEveryTagRowUnderTheBareName, aGlossaryTermNamedLikeTheFileKeepsEveryTagRowUnderTheBareName; plus a createFolder(name, parent, tags...) helper overload and a glossaryTermTags helper).
  • All 6 tests in the class pass on both the PostgreSQL+OpenSearch and MySQL+Elasticsearch merge-queue engines (verified locally against a real Postgres/MySQL + OpenSearch/Elasticsearch stack via the in-process Dropwizard app + Testcontainers; repairAll is invoked through TestSuiteBootstrap.getJdbi(), and assertions hit both the REST API (?fields=tags) and tag_usage row counts by FQN hash).

PR checks run only the Java unit tests; the integration tests run in the merge queue and JavaUIIT / search-it nightly. For PR creation, record focused checks and list broader checks as pending. Merge readiness
requires the full impacted plan. Tests are selected from
.github/java-tests/impact-map.json:

make java_affected ARGS="--scope focused" # select focused checks; --scope full for merge readiness
make java_affected_run ARGS="--scope focused" # run once if no applicable evidence exists
make java_affected ARGS="--publish-results" # publish saved results without rerunning

Without gh, drop --update-pr, paste target/java-tests/local-pr-results.md between the markers,
and post target/java-tests/local-pr-results-details.md as a PR comment.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  • Ran the full ContextFileFqnRepairMigrationIT class locally on PostgreSQL+OpenSearch and MySQL+Elasticsearch (6/6 tests pass on each). The new subfolder test reproduces the bug report's exact scenario (file x in folder Y damaged to bare name x with an edit tag, plus a subfolder x under Y tagged PII.NonSensitive + PersonalData.SpecialCategory): after repairAll, the subfolder still shows only its two original tags and the bare-name tag_usage row count is unchanged, confirming the file's rows were not moved onto the subfolder's hash. The glossary-term test creates a glossary named like the folder and a term named like the file, asserting the term keeps only its own tags after repair.

UI screen recording:

Not applicable — backend-only migration fix (no UI changes).

Checklist:

  • I have read the CONTRIBUTING document.
  • 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.
  • 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.

Automatic Fixes PRs can be configured here.

RetriggerView in GreptileConfidence Score: 4/5

The Java guide requirements must be satisfied before merging; no new functional failure was established.

Findings

  1. P2 Cleanup failures stay hidden ▶
  2. P2 Helper exceeds the parameter limit ▶
  3. P2 Unchanged values lack `final` ▶
  4. P2 Collision methods are too long ▶

Summary

The PR checks both stored and derived FQNs across entity tables before moving tag_usage rows.

  • File repairs keep tags separate when another entity shares either name.

Reviews (3) · Last reviewed commit: "Address review: extract helpers, registe..." · Reviewed by Greptile

@detail-app
detail-app Bot requested a review from a team as a code owner November 21, 2026 04:06
@detail-app
detail-app Bot requested a review from mohityadav766 November 21, 2026 04:06
Comment on lines +169 to +183
void aGlossaryTermNamedLikeTheFileKeepsEveryTagRowUnderTheBareName(TestNamespace ns) {
String folderName = ns.shortPrefix("Y");
String name = ns.shortPrefix("x");
Glossary glossary =
ns.trackRoot(
Entity.GLOSSARY,
SdkClients.adminClient()
.getHttpClient()
.execute(
HttpMethod.POST,
GLOSSARIES,
new CreateGlossary()
.withName(folderName)
.withDescription("Named like the file's folder"),
Glossary.class));

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 Collision methods are too long

The new glossary-term test has roughly 40 nonblank lines. The Java guide requires methods to stay around 15 lines and do one named thing. Extract the fixture setup and shared assertions into helpers. The new subfolder test and expanded repair method also exceed this limit. This repository requirement must be satisfied before merging.

Context Used: CLAUDE.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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in e548996: extracted the two collision LOG.warn blocks into a logCollisions helper, and extracted the glossary-term/subfolder fixture setup (createGlossary, createGlossaryTerm, glossaryTermNamedLikeTheFile) and shared after-repair assertions (assertTagsStayUnderTheirOwner) so each new test and repair stay short and do one named thing.

@yan-3005 yan-3005 added the To release Will cherry-pick this PR into the release branch label Nov 23, 2026
@yan-3005

Copy link
Copy Markdown
Contributor

Verified locally (MySQL + Elasticsearch, parallel lane):

  • ContextFileFqnRepairMigrationIT with main's ContextFileFqnRepair: 2/4 fail. aGlossaryTermNamedLikeTheFileKeepsEveryTagRowUnderTheBareName ends with the glossary term holding the file's PersonalData.Personal tag, and the subfolder case fails the same way. So the bug is real.
  • With this PR: 4/4 pass.

Note for reviewers: this edits the v210 runOnce step that is in the 2.1.0-release tag. A database already upgraded to 2.1.0 has the step's marker and won't re-run it. A new v211 step wouldn't help those databases either: 2.1.0 already re-derived the file FQNs, and tag_usage (keyed by FQN hash, no owner column) can't tell which merged rows were the file's. Fixing it in place covers every install that hasn't upgraded yet, which is the best available.

- Extract the two collision LOG.warn blocks in ContextFileFqnRepair.repair
  into a logCollisions helper so the method stays short and does one thing.
- Extract fixture setup (createGlossary, createGlossaryTerm,
  glossaryTermNamedLikeTheFile) and shared after-repair assertions
  (assertTagsStayUnderTheirOwner) so each new test stays short.
- Register the new Context Center files with TestNamespace and add an
  @AfterEach that deletes the folders the new tests create (folders are
  not in TestNamespaceExtension's cleanup map), so runs leave no fixtures
  behind.
Comment on lines +73 to +75
} catch (RuntimeException ignored) {
// Best-effort, like NamespaceCleanup: a failed delete never fails a green 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.

P2 Cleanup failures stay hidden

deleteFolders silently catches every RuntimeException. The Java guide requires catch blocks to log failures at minimum. Log the folder ID and exception so failed cleanup leaves an explanation. This repository requirement must be satisfied before merging.

Context Used: CLAUDE.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!

Comment on lines +241 to +247
private static void assertTagsStayUnderTheirOwner(
ContextFile file,
String derivedFqn,
List<String> otherTagsBefore,
Supplier<List<String>> otherTagsAfter,
String bareName,
int rowsUnderBareName) {

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 Helper exceeds the parameter limit

assertTagsStayUnderTheirOwner takes six parameters. The Java guide allows at most five and requires related values to travel in a record or parameter object. Group the fixture details before passing them to this helper. This repository requirement must be satisfied before merging.

Context Used: CLAUDE.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!

Comment on lines +346 to +348
private static Glossary createGlossary(
TestNamespace ns, String name, String description, String... tags) {
CreateGlossary request = new CreateGlossary().withName(name).withDescription(description);

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 Unchanged values lack final

The new test helpers omit final from parameters and locals that never change. The Java guide requires final on those values. Apply it in createGlossary, createGlossaryTerm, and the other new helpers, including assertTagsStayUnderTheirOwner. This repository requirement must be satisfied before merging.

Context Used: CLAUDE.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!

@yan-3005 yan-3005 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.

Verified: ContextFileFqnRepairMigrationIT collision cases fail on main (file tags merge into the same-named glossary term/subfolder) and pass 4/4 with this fix. Latest commit is a behavior-neutral helper extraction + fixture cleanup.

@yan-3005
yan-3005 merged commit 585284f into main Nov 23, 2026
63 checks passed
@yan-3005
yan-3005 deleted the detail/bug-fix/fixes-38346-check-derived-fqn-across-all-entity-ta-118f03 branch November 23, 2026 15:49
@github-actions

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

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

Copy link
Copy Markdown

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

@gh-bot-collate

Copy link
Copy Markdown

🤖 Not backported to 2.0. Claude looked at the conflict and declined to resolve it:

Backport aborted: PR #38383 does not apply to 2.0

Source PR: #38383 — "Fixes #38346: check derived FQN across all entity tables before
moving tags"
Merge commit: 585284f
Target branch: 2.0

Reason

PR #38383 is a follow-up fix to ContextFileFqnRepair, a migration utility class that was
introduced on main by PR #37960 ("fix(migration): move Context Center file tags on upgrades
where later tables do not exist yet", commit a207ac4740). That prerequisite commit has never
been backported to 2.0:

$ git merge-base --is-ancestor a207ac4740 HEAD
NOT ANCESTOR

Both files this PR touches —
openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/ContextFileFqnRepair.java
and
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/ContextFileFqnRepairMigrationIT.java
— do not exist on 2.0 at all (hence the cherry-pick's "deleted by us" conflicts: the file
exists at the merge-base and in the commit being picked, but was never added on this branch).

PR #38383 only edits existing logic in that class (splitting the single "FQN already held by
another entity" check into separate stored-FQN and derived-FQN collision checks, plus adding
tests that build on fixtures from the original migration's test suite). There is no sensible way
to apply just this diff without first bringing in the entire ContextFileFqnRepair migration
step (#37960) it depends on — doing so would be a much larger, unrelated change far outside the
scope of this backport.

Recommendation

If the ContextFileFqnRepair migration (#37960) is backported to 2.0 first, this PR (#38383)
should be re-attempted as a follow-up backport at that point. Until then, this backport should
not be merged.

State left behind

Per the workflow instructions, the cherry-pick has been left in progress (not aborted, staged,
or committed) so a later step can inspect/clean it up as needed.

resolver run

yan-3005 added a commit that referenced this pull request Nov 24, 2026
…g tags (#38383) (#38513)

* fix(migration): check derived FQN across all entity tables before moving tags

* Address review: extract helpers, register fixtures for cleanup

- Extract the two collision LOG.warn blocks in ContextFileFqnRepair.repair
  into a logCollisions helper so the method stays short and does one thing.
- Extract fixture setup (createGlossary, createGlossaryTerm,
  glossaryTermNamedLikeTheFile) and shared after-repair assertions
  (assertTagsStayUnderTheirOwner) so each new test stays short.
- Register the new Context Center files with TestNamespace and add an
  @AfterEach that deletes the folders the new tests create (folders are
  not in TestNamespaceExtension's cleanup map), so runs leave no fixtures
  behind.

---------



(cherry picked from commit 585284f)

Co-authored-by: detail-app[bot] <180357370+detail-app[bot]@users.noreply.github.com>
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

To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] Migration: Context Center file tags can merge into other entities when derived FQN collides

2 participants