Skip to content

[Detail Bug] API: Tag/glossary label fields oscillate after recursive soft-delete due to bundle warmup including deleted entities #36024

Closed

Description

@detail-app

Detail Bug Report

https://app.detail.dev/org_3377c26d-da48-4ccd-b83a-22c542f4fe83/bugs/bug_be860ece-24ed-4169-a6dd-a4315099e26b

Introduced in #27864 by @harshach on May 2, 2026

Summary

  • Context: The Redis bundle cache is pre-warmed per entity type by CacheWarmupApp (shipped enabled, hourly) through BundleWarmupBatcher, which batch-fetches each asset's tags and bakes them into the cached bundle with tagsLoaded=true. On a cache-miss GET, EntityRepository.fillReadBundle instead computes tags via fetchAndPutTagsWithCertification → TagLabelUtil.populateTagLabel.
  • Bug: The warmer's tag query (getTagsInternalByTargetHashes) LEFT JOINs tag / glossary_term_entity on fqnHash with no deleted filter, so it enriches tag labels from the stored JSON of soft-deleted tags/glossary terms, while the canonical read path fetches enrichment entities with Include.NON_DELETED and serves the same label unenriched.
  • Actual vs. expected: For the same tag_usage row, a warmed cache-hit GET serves the label with the deleted tag/term's name/displayName/description/style, while a cache-miss GET of the same asset serves it without those fields — the served value oscillates with the warmup/TTL schedule instead of both paths agreeing.
  • Impact: After a user recursively soft-deletes a Glossary or Classification, assets still carrying those terms/tags flip between showing the deleted term's stale display name/style/description (cache hit) and a bare, unenriched label (cache miss) for up to the 48h bundle TTL; the hourly warmup keeps re-baking the enriched variant, so the inconsistency self-perpetuates.

Code with Bug

Warmer tag fetch (openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ClassificationTagDAOs.java, getTagsInternalByTargetHashes):

SELECT tu.source, tu.tagFQN, tu.labelType, tu.targetFQNHash, tu.state, tu.reason, tu.appliedAt, tu.appliedBy, tu.metadata,
CASE
  WHEN tu.source = 1 THEN gterm.json
  WHEN tu.source = 0 THEN ta.json
END as json
FROM tag_usage tu
LEFT JOIN glossary_term_entity gterm ON tu.source = 1 AND gterm.fqnHash = tu.tagFQNHash
LEFT JOIN tag ta ON tu.source = 0 AND ta.fqnHash = tu.tagFQNHash
WHERE tu.targetFQNHash IN (<targetFQNHashes>)   -- <-- BUG 🔴 deleted entities not filtered from join

Mapper enriches from joined JSON whenever present:

if (source == TagLabel.TagSource.CLASSIFICATION) {
  Tag tag = JsonUtils.readValue(json, Tag.class);
  label.setName(tag.getName());
  ...
} else if (source == TagLabel.TagSource.GLOSSARY) {
  GlossaryTerm glossaryTerm = JsonUtils.readValue(json, GlossaryTerm.class);
  label.setName(glossaryTerm.getName());   // <-- BUG 🔴 enriches from soft-deleted term JSON
  ...
}

Warmer bakes enriched labels into bundle and marks them authoritative:

dto.tags = stripCertificationTags(
    tagsByFqnHash.getOrDefault(entry.getKey(), Collections.emptyList()), certClassification);
dto.tagsLoaded = true;   // <-- BUG 🔴 cache hit skips canonical tag fetch/re-filtering

Canonical cache-miss enrichment excludes deleted tag/term entities:

public static List<Tag> getTags(List<String> tagFQNs) {
  return Entity.getEntityByNames(Entity.TAG, tagFQNs, "", NON_DELETED);
}
public static List<GlossaryTerm> getGlossaryTerms(List<String> tagFQNs) {
  return Entity.getEntityByNames(Entity.GLOSSARY_TERM, tagFQNs, "", NON_DELETED);
}

Explanation

  • Recursive soft-deletes of a Glossary/Classification soft-delete child term/tag rows but do not purge tag_usage rows (bulk soft-delete path flips deleted=true on entity JSON and never calls per-entity postDelete, where tag usage cleanup normally happens). This leaves live assets with tag_usage rows pointing at soft-deleted tag/term entities.
  • On cache miss, populateTagLabel enriches labels by fetching tags/terms with Include.NON_DELETED; for soft-deleted entities it gets no enrichment object and returns an unenriched label.
  • On cache hit after warmup, the warmer’s SQL join returns the soft-deleted tag/term JSON (because the join lacks a deleted=false predicate), the row mapper enriches label fields from that JSON, and BundleWarmupBatcher stores the enriched labels with tagsLoaded=true. fillReadBundle then serves those labels verbatim, skipping the canonical DB fetch.
  • Because warmup runs hourly and bundle TTL is 48h, the “enriched from deleted JSON” variant keeps getting re-baked; the same asset’s GET response changes depending on cache warmth.

Codebase Inconsistency

The warmer is intended to mirror canonical tag enrichment, but the canonical path explicitly uses NON_DELETED for tag/term lookups (see TagLabelUtil.getTags/getGlossaryTerms), while the warmer path does not filter deleted rows in SQL.

Recommended Fix

Filter deleted entities out of the warmer join in getTagsInternalByTargetHashes (and also getTagsInternalByPrefix for consistency) so the joined JSON is null for soft-deleted tags/terms and the existing “orphan” behavior returns an unenriched label matching the cache-miss path:

LEFT JOIN glossary_term_entity gterm ON tu.source = 1 AND gterm.fqnHash = tu.tagFQNHash AND gterm.deleted = FALSE
LEFT JOIN tag ta ON tu.source = 0 AND ta.fqnHash = tu.tagFQNHash AND ta.deleted = FALSE

History

This bug was introduced in commit 620d1b6 (PR #27864, 2026-05-02), which added bundle pre-warming and started baking the warmer’s enriched labels into bundles with tagsLoaded=true, making warmed cache-hit GETs diverge from the canonical cache-miss path.

Activity

  1. added a commit that references this issue on Nov 15, 2026
    feef77f
  2. added a commit that references this issue on Nov 19, 2026
    a113d06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done ✅

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions