Skip to content

[2.0] Fixes open-metadata/openmetadata-collate#8646: a hard delete keeps the tags of entities that share its FQN (#38126) - #38230

Merged
mohityadav766 merged 1 commit into
2.0from
backport/2.0/38126-hard-delete-same-name-tag-wipe
Nov 19, 2026
Merged

mohityadav766 merged 1 commit into
2.0from
backport/2.0/38126-hard-delete-same-name-tag-wipe

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes open-metadata/openmetadata-collate#8646

Backport of #38126 to 2.0. The bug was reported on 2.0.8 and is the same on this branch. tag_usage and field_relationship key their rows by FQN hash alone, and an FQN is unique only within a type. Before this change, 2.0's hard delete removed every row at and under the deleted entity's FQN, whatever entity those rows belonged to. Hard-deleting a pipeline service named like a database service removed the tags and tiers of every table in the database service. 2.0 already has the change this builds on: HardDeleteCleanupIT and ADR:2026-11-03-a-hard-delete-removes-only-rows-of-the-deleted-entity came with #37162.

What changed (same as #38126):

  • FqnKeyedRowCleanup runs the FQN-prefix deletes for both the single-entity cleanup and the bulk cascade. First it looks for entities the delete leaves in place:
    • Another type's entity with the same FQN. Nothing at or under the FQN is deleted.
    • A field at a free-form FQN, such as a metric named like a column's FQN. Nothing at or under it is deleted.
    • Entities that nest under the FQN without being its descendants. Everything except their subtrees is deleted.
  • Recursive deletes: a root that keeps rows under its FQN for such an entity lets its descendants remove their own rows (CASCADE_ROOT_FQN_SHARED).
  • Opt-ins: data models, metrics, knowledge pages, folders and context files can nest under unrelated FQNs (nestsUnderUnrelatedFqns()). Data models name the dashboard service as their FQN parent (fqnParentType()).
  • DAO: deleteTagLabelsByTargetPrefixOutside, deleteAllByPrefixOutside and the probe query listEntityFqnHashes.
  • Decision records: ADR:2026-11-18-a-hard-delete-keeps-the-rows-of-entities-that-share-its-fqn comes along, and the 11-03 record gets its v3 amendment, so the code's citations resolve on 2.0.

Differences from #38126:

  • DAO location. 2.0 still keeps TagUsageDAO and FieldRelationshipDAO nested in CollectionDAO; the ClassificationTagDAOs / CoreRelationshipDAOs split is main-only. The three new statements live there, with the same SQL.
  • Tagged fields. 2.0 has no ChildFieldResolver registry. Each repository whose entities have tagged inline fields overrides taggedFieldContainers() instead. So hasTaggedFields() defaults to false, and those ten repositories return true: tables, topics, data models, containers, search indexes, ML models, pipelines, API endpoints, worksheets and Drive files. These are the same types main covers through its registry plus FileRepository.
  • Delete order in cleanup(). 2.0's cleanup() deleted field_relationship before entity_extension, and tag_usage after it. Both deletes now run in one call after entity_extension. That is main's order, and the order 2.0's bulk cascade already used, so a direct delete and a cascade delete over the same rows take the tables in the same order.
  • Entity.getEntityRepositories() returns 2.0's non-generic EntityRepository<? extends EntityInterface>.
  • Left out:
    • the MetricGroupRepository opt-in, since metric groups don't exist on 2.0;
    • the impact-map.json entry, since 2.0 has no impact map;
    • main-only code that sat inside the conflicting hunks: the IN_HARD_DELETE_CASCADE flag, main's restructured delete() and cleanup(), and ContextFileRepository methods 2.0 doesn't have.
  • FqnKeyedRowCleanup, the new ADR and HardDeleteCleanupIT are line-for-line the same as on main, except that an IT comment which named ChildFieldResolver is reworded. FqnKeyedRowCleanupTest differs only in naming CollectionDAO as the DAOs' host.

Type of change:

  • Bug fix

High-level design:

Same as #38126, which covers the alternatives considered and the cost: two more queries per hard delete, and two more before a recursive delete's cascade. No migration and no API change. Rows a past delete already removed are not restored.

Tests:

Use cases covered

Same as #38126:

  • An async recursive hard delete of a pipeline service named like a database service keeps the tags and tier of the database's tables and columns. This is the reported scenario, through the endpoint the UI uses.
  • A hard delete of the database service keeps the same-name pipeline service's pipeline tags, and a table re-created at the deleted FQN starts with no tags.
  • A hard delete of a stored procedure named like a table, of a chart named model, or of a glossary keeps the tags of the table, of the service's data models, and of a metric named like one of the glossary's terms.
  • A hard delete of a database service keeps the tags of a metric named like its database (service.db).
  • A hard delete of a metric named like a table column's FQN, or a Drive file column's, keeps that column's tags.

Unit tests

Backend integration tests

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Compared 2.0's cleanup(), its bulk cascade and the two DAO statements with main's code before #38126. They delete by FQN prefix with no type check, as main did, so the bug and the fix both apply. #38126 has before/after recordings of the reported scenario in the UI.

UI screen recording / screenshots:

Not applicable — backend-only fix.

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. (no schema change)
  • For UI changes: I attached a screen recording and/or screenshots above. (no UI change)
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • 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.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 4/5

The Java convention requirement must be satisfied before merging.

Findings

  1. P2 New Java skips required conventions ▶

Summary

This backport protects surviving entities' tags and field relationships when a hard delete reaches a shared fully qualified name.

  • Hard deletes keep tags and field links shared by surviving entities.

mohityadav766 documents that shared rows may remain and defers collisions between parent-built names and inline fields until rows record entity types. The added Java code still needs the required convention cleanup noted below.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Hard delete] --> B[Find surviving entities sharing the name]
  B --> C{Which rows are shared?}
  C -->|Same name or inline field| D[Keep shared rows]
  C -->|Nested surviving entities| E[Delete outside surviving subtrees]
  C -->|None| F[Delete the full prefix]
  A --> G{Recursive root keeps descendant rows?}
  G -->|Yes| H[Each descendant cleans its own rows]
  G -->|No| I[Covered descendants rely on root cleanup]
Loading

Reviews (1) · Last reviewed commit: "[2.0] Fixes open-metadata/openmetadata-c..." · Reviewed by Greptile

…eps the tags of entities that share its FQN (#38126)

Backport of #38126. tag_usage and field_relationship key their rows by FQN
hash alone, so a hard delete removed the rows of every entity at or under the
deleted entity's FQN, whatever its type. Hard-deleting a pipeline service named
like a database service removed the tags and tiers of every table in it.

Differences from main:
- The new TagUsageDAO and FieldRelationshipDAO statements live in
  CollectionDAO, where 2.0 keeps those DAOs.
- 2.0 has no ChildFieldResolver registry, so hasTaggedFields() defaults to
  false and the ten repositories that override taggedFieldContainers() return
  true.
- cleanup() runs both FQN-prefix deletes after entity_extension, the order
  2.0's bulk cascade already uses.
- No MetricGroup opt-in or impact-map entry; neither exists on 2.0.

(cherry picked from commit ad4d5f2)
@mohityadav766
mohityadav766 requested a review from a team as a code owner November 19, 2026 16:12
@mohityadav766
mohityadav766 requested review from IceS2 and removed request for a team November 19, 2026 16:12
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

  • Linked issue open-metadata/openmetadata-collate#8646 does not exist or is not accessible.

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.

@gitar-bot

gitar-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

Changing hard-delete cleanup to probe shared FQNs and filter tag and relationship rows affects stored-data integrity; mistakes could erase metadata for surviving entities.

Backport of the hard-delete fix so that deleting an entity no longer removes tags and tiers belonging to other entities that share its FQN, such as a pipeline service named like a database service. Hard deletes now check entity type before removing tag_usage and field_relationship rows, with new DAO statements, an ADR, and integration coverage. No issues found.

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 +93 to +99
private Map<String, OwnedRows> ownedRows(List<String> fqns) {
Map<String, String> hashes = new LinkedHashMap<>();
fqns.forEach(fqn -> hashes.put(fqn, FullyQualifiedName.buildHash(fqn)));
Map<String, OwnedRows> owned = new LinkedHashMap<>();
if (taggable) {
List<String> hashList = List.copyOf(hashes.values());
Set<String> kept = keptHashes(hashList);

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 New Java skips required conventions. The Java guide requires final on parameters and local variables that are not reassigned, getFirst() instead of get(0), and constants for repeated strings. The new declarations here omit final. The added tests also use get(0), and nestedHolderHashes() repeats "under". Apply these conventions across the added Java code 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!

@mohityadav766
mohityadav766 merged commit cea73b8 into 2.0 Nov 19, 2026
63 of 70 checks passed
@mohityadav766
mohityadav766 deleted the backport/2.0/38126-hard-delete-same-name-tag-wipe branch November 19, 2026 19:07
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.

1 participant