Skip to content

[2.1] Fixes #37164: Hold glossary terms that are not Approved as pending until approved - #38511

Merged
yan-3005 merged 3 commits into
2.1from
backport/2.1/pr-38239
Nov 24, 2026
Merged

yan-3005 merged 3 commits into
2.1from
backport/2.1/pr-38239

Conversation

@gh-bot-collate

@gh-bot-collate gh-bot-collate Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Automated backport of #38239 to 2.1.

Source PR #38239
Author @yan-3005
Merge commit fb4731f0adbab92df9d80236735bb1bd95014ba2
Method Conflicts resolved by Claude — worth a read of the diff.

Resolution notes

Backport notes: #38239 → 2.1

Conflict

Only openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java
conflicted, in addDataModel. Every other file in the PR applied cleanly.

The conflict was caused by an unrelated main-only refactor: a later main commit
(2cb0f81f0e, "Ontology concepts and properties get their own search index with
embeddings") extracted a getWholeStoredTable(tableId) helper that addDataModel on
main now calls to fetch the table row. That helper does not exist on 2.1 — the branch
still fetches the table inline with
get(null, tableId, getFields(Set.of(FIELD_OWNERS, FIELD_TAGS, COLUMN_FIELD, TABLE_CONSTRAINTS_FIELD)), NON_DELETED, false).

Resolution

Kept 2.1's inline get(...) call (its existing shape) and applied PR #38239's actual
change on top of it:

  • addDataModel gained the String updatedBy parameter (already expected by
    TableResource.addDataModel, which came in pre-staged from the merge and calls
    repository.addDataModel(id, dataModel, securityContext.getUserPrincipal().getName())).
  • The old ApprovedGlossaryTermGuard.checkNewlyApplied(...) call (which rejected the
    write with a 400) was replaced with
    List<HeldTerm> heldTerms = holdUnapprovedModelTerms(table, dataModel);, and
    storePendingGlossaryTerms(heldTerms, updatedBy) was added after dao.update(...),
    matching the rest of the PR's "hold as pending instead of rejecting" behavior.

No main-only refactor (the getWholeStoredTable extraction) was pulled into 2.1; only
the glossary-term-holding behavior from #38239 was ported.

What to check by hand

  • addDataModel on 2.1 now reads: inline get(...) → holdUnapprovedModelTerms →
    (unchanged merge logic) → dao.update(...) → storePendingGlossaryTerms(heldTerms, updatedBy)
    → cache invalidation / RDF / search rebuild. Confirm this matches the intended
    behavior of the rest of the PR (which was already staged conflict-free).
  • HeldTerm, holdUnapprovedModelTerms, takeHeld, storedColumn,
    heldTermHashesByTarget, takeTerms, and storePendingGlossaryTerms all pre-existed
    on this branch from the clean parts of the cherry-pick (in ApprovedGlossaryTermGuard
    and EntityRepository) — nothing new was introduced to resolve this conflict.
  • The cherry-pick is left in progress with TableRepository.java still unmerged in the
    index; only the working-tree content was edited, per the workflow's staging step.

Opened from openmetadata-collate, which holds the credentials needed to open a PR here. It merges itself once this branch's required checks pass — no review needed. If a check fails it stays open and the author of #38239 is asked to look.

resolver run

RetriggerView in GreptileConfidence Score: 4/5

Fix the approval/removal race and satisfy the repository's comment rule before merging.

Findings

  1. P1 Removed terms appear again ▶
  2. P2 Events name the wrong author ▶
  3. P2 Comments repeat the code ▶

Summary

Writes now keep newly applied, unapproved glossary terms hidden in tag_usage until approval.

  • Writes keep unapproved glossary terms hidden until the term is approved.
  • Pending glossary terms stay hidden while visible labels are rewritten.
  • Approved glossary terms reappear on assets that were waiting for them.
  • CSV imports refuse unapproved glossary terms on columns that would receive them.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Asset write] --> B{Term approved?}
  B -->|Yes| C[Write visible label]
  B -->|No| D[Store hidden pending label]
  D --> E[Term approved]
  E --> F[Read pending labels]
  F --> G[Patch assets as governance bot]
  G --> H[Update version, event, search and RDF]
  D --> I[User removes pending application]
  I --> J[Delete pending row]
Loading

Reviews (1) · Last reviewed commit: "Fixes #37164: Hold glossary terms that a..." · Reviewed by Greptile

…til approved (#38239)

* Fixes #37164: Hold glossary terms that are not Approved as pending until approved

A write that newly applies a glossary term that is not Approved no longer
fails with a 400. The term is taken out of the write and stored in tag_usage
with the new state Pending, which every tag read leaves out: API responses,
search documents, caches, counts, the list API tag filter, ontology and
knowledge center reads, and CSV export. When the term is approved, its pending
rows are flipped in background batches of 500 and every asset holding them is
evicted from the cache and reindexed. When it is rejected, they are deleted.

Writes that clear and rewrite an asset's tags (CSV import, data model, bulk
re-store) keep pending rows. Bulk create and bulk update store them with the
entity write, so a failed write leaves none behind. The approval gate no
longer refuses such an edit when staging it; the term is held when the
approved edit is published. dbt no longer skips terms that are not Approved
(reverts #37571); the server holds them. CSV import keeps its per-row
refusal.

* Recover pending labels of approved terms and keep the column CSV refusal

- A batch that fails to show is retried, up to three times, and the
  holders of a batch are resolved before its rows are flipped.
- A write that held a term checks it once the write commits, so a term
  approved while the write ran is shown.
- The server sweeps for pending labels of Approved terms on start.
- The holder probe binds at most 20,000 values per query.
- Approval and rejection are acted on in GlossaryTermRepository.postUpdate,
  after the term is stored, bulk updates included.
- The approval check for mutual exclusion counts the tags the shown terms
  imply, fetched once per batch.
- Column CSV import keeps refusing a term that is not Approved, in the dry
  run and the import, as entity CSV import does.

* Re-check approval before each retry and page the startup sweep

A retry shows nothing for a term deprecated or rejected since its approval. The startup sweep pages through every term with pending labels in FQN order instead of one unordered page.

* Count the Pending tag label state in the enum compatibility test

Pending is appended as ordinal 2, so stored Suggested (0) and Confirmed (1) values keep their meaning.

* Close the review gaps: list pending assets, remove them by PATCH, retry search

- GET /v1/glossaryTerms/{id}/pendingAssets lists the assets a term's approval
  will show it on, page by page.
- A PATCH by the user who applied a pending term that sends a target's labels
  without it removes it there. The targets come from the patch paths, so an
  edit of another attribute or another field removes nothing. PUT, imports and
  other users' writes never remove a pending term. The writer is read before
  the flush, which reverts a no-change write to the stored version.
- An asset whose search document fails to index when a term is approved goes
  on the search retry queue, so search catches up with the API.

* Remove pending terms only through assets/remove, filter pendingAssets by view

- A write of an asset's labels no longer removes a pending term, by any user:
  index-level PATCH ops, column inserts and CSV imports made that rule
  unreliable. The term's assets/remove drops its pending labels on the asset
  and every field under it. The table CSV import uses the plain PATCH again.
- pendingAssets lists only the assets the caller may view.
- A data model's held terms record the caller as applier, not the table's
  previous writer.
- The ADR records the endpoint, the removal rule and the search retry.

* Authorize and scope pending-term removal through assets/remove

- assets/remove authorizes each asset for EditGlossaryTerms before dropping
  its pending labels, since a pending-only removal patches nothing.
- It drops the asset's own pending labels (the entity and its inline fields),
  not those of other entities nested under its FQN; a column drops its subtree.
- Assets are resolved by id, so a reference without an FQN works, and held
  removals drop pending labels too.

* Keep Pending internal and show approved terms through the entity pipeline

- Pending is a storage state only the tag DAO knows, one past the public
  TagLabel.State values, so no client can send or receive it; the public enum
  and generated models are back to Suggested and Confirmed.
- Approval adds the term to each holding asset as an ordinary PATCH by the
  governance bot, so the asset records a version and a change event and its
  cache, search document and RDF are updated by the pipeline; the PATCH's
  upsert turns the pending rows into shown ones. The direct-SQL flip and the
  hand-made refresh are gone.
- assets/remove reports an asset the caller may not edit as failed.

* Show an approved term on the targets that take it, keeping what it was sent with

- When an asset refuses the term on all its targets at once, as for a
  mutually exclusive tag on one column, the term is shown on each target
  alone, so only the refusing targets stay pending.
- The term keeps the label type, reason and metadata it was sent with.
- A deleted asset is skipped rather than retried.

* Keep the approval pass going when an asset's per-target fallback fails

The fallback runs inside the per-asset handler, so a failure there marks the pass incomplete and moves on to the next asset instead of ending the pass.

* Stop PipelineBulkStatusChangeEventsTest leaving a null repository in Entity's map

Stubbing Entity.registerEntity with when(...) on a CALLS_REAL_METHODS static
mock runs the real method once with null matchers, which puts a null
repository in the process-wide repository map. FqnKeyedRowCleanup iterates
that map, so EntityRepositoryRestoreTest's hard-delete tests threw an NPE
whenever they ran later in the same fork. The fixture's default answer now
skips registration instead.

* Hold a term's classifications with it, list only its own assets, keep it across bulk retries

- A held term's classification tags were still added as derived labels to the
  entity the write returns and hands to postCreate. The derived labels only a
  held term carries are now held with it.
- pendingAssets listed every entity above a pending target. It now lists the
  entity that holds the target, as itself or as one of its fields.
- A bulk create retried after a concurrent duplicate reused entities whose held
  terms had been taken out, and the rollback had dropped their pending rows.
  A failed chunk gets its terms back before the retry.

* Record approval's change event, keep later bulk chunks' terms, list every holding asset

- Approval patches each asset from a background job, which has no response for
  the response filter to record a change event from, so alerts and the
  activity feed never saw the term arrive. It now records the event itself.
- When a bulk create chunk failed, only that chunk got its held terms back,
  while callers fall back to creating every remaining entity one by one, so
  the chunks after it were created without their terms. Every chunk from the
  failed one on gets them back.
- pendingAssets kept only the longest matching holder of each target, so an
  entity whose FQN runs into a held column's (a metric named after it) hid the
  table. It now keeps a holder when the target is the entity itself or one of
  its own fields.

* Keep held terms on retyped fields and moved containers; page the event check

- A column or field whose dataType changes is dropped and re-added under the
  same FQN, and the unfiltered tag delete also removed the term held on it, so
  approval never showed it. A field re-added under its name now clears only its
  shown labels (columns of tables, containers and data models; topic,
  API endpoint and search index fields).
- A container moved to another parent deleted the term held on it. Its pending
  labels now move to its new FQN.
- The approval IT reads every page of change events, since other tests update
  tables concurrently.

* Log when dbt applies a glossary term that is not Approved yet

The server holds such a term on the asset until it is approved, so the
dbt run succeeds but the term does not show. Log why, and test that a
term of every status is still sent.

---------

Co-authored-by: ulixius9 <mayursingal9@gmail.com>
(cherry picked from commit fb4731f)
@gh-bot-collate
gh-bot-collate Bot requested review from a team as code owners November 23, 2026 15:31
@gh-bot-collate
gh-bot-collate Bot requested review from stout-yeoman and removed request for a team November 23, 2026 15:31
@gh-bot-collate
gh-bot-collate Bot requested review from manerow and removed request for a team November 23, 2026 15:31
@gh-bot-collate gh-bot-collate Bot added the safe to test Add this label to run secure Github workflows on PRs label Nov 23, 2026
@gh-bot-collate

Copy link
Copy Markdown
Author

🤖 This backport will not merge itself: 2.1 has no required status checks, so there is nothing for auto-merge to wait on. Merge it by hand once CI is green.

Comment on lines +193 to +202
Map<String, TagLabel> labelsByTarget = new HashMap<>();
dao()
.listPendingLabels(GLOSSARY, termHash, targets)
.forEach(row -> labelsByTarget.put(row.getKey(), termLabel(termFqn, row.getValue())));
int shown = 0;
boolean complete = true;
for (TargetHolder holder :
labelsByTarget.isEmpty() ? Set.<TargetHolder>of() : holders(targets)) {
try {
shown += showOnHolder(termFqn, holder, labelsByTarget);

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.

P1 Removed terms appear again

showBatch keeps pending labels in memory while it patches assets. If assets/remove deletes a pending label after this read but before the patch, the patch still adds the term. The write inserts the deleted row again, undoing a successful removal. Check that the application is still pending when the asset write commits, using a shared lock or another atomic check.

Comment on lines +738 to +741
"SELECT targetFQNHash, labelType, reason, metadata FROM tag_usage WHERE source = :source AND tagFQNHash = :tagFQNHash "
+ "AND state = "
+ PENDING_STATE
+ " AND targetFQNHash IN (<targetFQNHashes>)")

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 Events name the wrong author

PendingLabelMapper drops appliedBy and appliedAt. During approval, updateTags stamps the in-memory label with the governance bot, while the write keeps the original author in tag_usage. showApprovedTerm records its event from that in-memory entity, so the event names a different label author than a later GET. Carry the stored author and time through approval and into the recorded entity.

if (request.getColumnName() != null && !request.getColumnName().isEmpty()) {
columnUpdatesToProcess = buildColumnUpdatesFromSearch(securityContext, request);

// If dry-run, just return the list of columns that would be updated

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 Comments repeat the code

The new comments “If dry-run” and “Add all columns to success responses” restate the adjacent condition and loop. The repository guide requires comments to explain why, not repeat obvious operations. Remove these comments or explain a non-obvious reason for this behavior. 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!

# Conflicts:
#	openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java
@yan-3005

Copy link
Copy Markdown
Contributor

Merged the latest 2.1 into this backport (1881425) to clear the conflict.

Conflict: TableRepository.addDataModel. Since this backport was opened, 2.1 changed how the stored table is loaded (getWholeStoredTable, from the schemaDefinition fix), while this PR replaces the reject-on-unapproved check with holding the terms as pending. Resolved to match main exactly: getWholeStoredTable(tableId) + holdUnapprovedModelTerms(...) + the updatedBy parameter (TableResource already passes it).

Verified on the merged 2.1 code (MySQL + Elasticsearch):

  • Unit: ApprovedGlossaryTermGuardTest 17, TagLabelUtilTest 23, ColumnRepositoryImportTest 12, PipelineBulkStatusChangeEventsTest 2 (54/0).
  • IT: GlossaryTermApprovedTaggingIT 44/0, ChangeRequestUnapprovedTermIT 5/0, TableResourceIT 189/0 (399 total, 0 failures; the 11 skips are inherited base-entity/cache/CSV cases, none from this PR).

…e term again in a session

One user's edits to a glossary term within a session are consolidated into one
version, and postUpdate then receives the version before the session as the
original. A term deprecated and approved again by the same user looked
unchanged, so the labels held while it was deprecated stayed hidden until the
next restart's sweep. postUpdate now also counts the status as changed when
the request's own change description records it.

(cherry picked from commit 7f05109)
@yan-3005

Copy link
Copy Markdown
Contributor

Added the same-session deprecate-then-approve fix from #38589 (a576c8a2041, cherry-picked with -x). On 2.1: approvingAgainInTheSameSessionShowsWhatWasHeldMeanwhile fails without it (ConditionTimeout) and passes with it; GlossaryTermApprovedTaggingIT 33 / 0, unit 33 / 0.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants