Skip to content

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

Merged
yan-3005 merged 3 commits into
2.0from
backport/2.0-37164-pending-glossary-terms
Nov 24, 2026
Merged

yan-3005 merged 3 commits into
2.0from
backport/2.0-37164-pending-glossary-terms

Conversation

@yan-3005

@yan-3005 yan-3005 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #38239 to 2.0 (hand port: ClassificationTagDAOs, AssetTagLabelService, BulkEntityCreator and ApprovalGate do not exist on 2.0). Fixes #37164.

What it does (same as #38239)

A write that newly applies a glossary term that is not Approved is accepted, and the term is held as a pending tag_usage row (internal state 2, not in the public TagLabel.State enum). Pending rows are hidden from every read, the search index and the response. When the term is approved, each holding asset gets an ordinary PATCH by governance-bot (version, change event, cache, search, RDF), running as a bounded database task and guarded by the ETag of the version it was built from. A rejected term's pending rows are dropped. GET /v1/glossaryTerms/{id}/pendingAssets lists the holders. The dbt client-side skip (#37571) is reverted, since the server now holds the term.

Where 2.0 differs from main

  • Pending layer lives in CollectionDAO.TagUsageDAO (MySQL + Postgres SQL), every tag read filtered the same way as main.
  • assets/add now holds a non-Approved term instead of refusing it.
  • TaggedField (pipeline tasks, ML features, 2.0 only) gets a setter, so a held term can be taken out and shown again on those fields; covered by a new unit test.
  • assets/remove keeps 2.0's own behaviour, unchanged by this port: it authorizes every asset up front (a user who cannot edit the asset gets a 403 for the request) and deletes by FQN prefix, so held labels follow the same rule as shown ones there.
  • 2.0's read path does not return the classification a term carries, so the IT checks the held classification on the create response and the term itself after approval.
  • Not ported (no 2.0 counterpart): ApprovalGate held-edit checks, ChangeRequestUnapprovedTermIT, the knowledge/ontology DAO filters.

Tests (2.0, local)

  • Unit: Tests run: 172, Failures: 0, Errors: 0 (incl. ApprovedGlossaryTermGuardTest 18 / 0)
  • IT, MySQL + Elasticsearch: GlossaryTermApprovedTaggingIT Tests run: 31, Failures: 0, Errors: 0 (main's 32 minus the nested-asset removal test, which does not apply to 2.0's prefix delete)

The To release bot will also try a [2.0] cherry-pick of #38239 once it merges; that one will conflict and can be closed in favour of this PR.

RetriggerView in GreptileConfidence Score: 2/5

Do not merge until approval cannot undo removals, conflicting Draft labels can become pending, and deleted ML features lose their pending rows.

Findings

  1. P1 Removed terms come back ▶
  2. P1 Draft terms still fail writes ▶
  3. P1 Recreated features receive old terms ▶
  4. P2 Test skips required import ▶
  5. P2 Tests miss wrong held terms ▶

Summary

This PR accepts newly applied unapproved glossary terms and stores them as hidden pending labels.

  • Writes keep newly applied unapproved glossary terms hidden until approval.
  • Approval shows pending glossary terms on assets through regular edits.
  • Reviewers can list assets holding a glossary term pending approval.
  • dbt sends unapproved glossary terms to the server instead of skipping them.

Acknowledged omission: yan-3005 states that knowledge/ontology DAO filters were not ported because they have no 2.0 counterpart.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Asset write with glossary term] --> B{Term approved or already shown?}
  B -->|Yes| C[Normal asset write]
  B -->|No| D[Remove label from visible write]
  D --> E[Store pending tag row]
  E --> F{Term decision}
  F -->|Approved| G[Background worker reads holders]
  G --> H[PATCH each asset as governance-bot]
  H --> I[Version, event, cache, search and RDF]
  F -->|Rejected| J[Delete pending rows]
Loading

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

…ing until approved

Port of #38239 to 2.0. A write that newly applies a glossary term that is not
Approved is accepted and the term is held as a pending tag_usage row (internal
state 2), hidden from every read, the search index and the change event. When
the term is approved, each holding asset gets an ordinary patch by the
governance bot (version, change event, cache, search and RDF update); when it
is rejected, its pending rows are dropped.

2.0 specifics: the pending layer lives in CollectionDAO.TagUsageDAO; assets/add
holds instead of refusing; TaggedField (pipeline tasks, ML features) gets a
setter so held terms can be taken out and shown again; assets/remove keeps
2.0's prefix delete and up-front authorization.
@yan-3005
yan-3005 requested review from a team as code owners November 23, 2026 14:53
@yan-3005
yan-3005 requested review from mohittilala and sonika-shah and removed request for a team November 23, 2026 14:53
@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.

Comment on lines +194 to +202
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 come back

showBatch copies pending labels before editing their assets. If a user calls assets/remove after that copy is loaded, the worker can add the deleted label back. Removal does not change the asset version, so the PATCH's weak ETag still matches.

Check and claim the pending row within the same transaction that applies it, so approval cannot undo a completed removal.

Knowledge Base Used: Metadata entity lifecycle

*/
private void flushUpdate(boolean useOptimisticStore, boolean importMode) {
checkNewlyAppliedGlossaryTermsApproved();
List<HeldTerm> heldTerms = holdUnapprovedGlossaryTerms();

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 Draft terms still fail writes

The new hold runs after prepareInternal, which already calls checkMutuallyExclusive. A PATCH containing a shown term and a new Draft term from the same mutually exclusive glossary still fails before the Draft term can become pending. The same happens when a Draft term carries a conflicting classification tag.

Separate held terms before checking the labels that will actually be shown. Keep those checks when approval later applies the term.

Comment on lines +643 to +646
feature.getName(),
feature.getFullyQualifiedName(),
feature::getTags,
feature::setTags))

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 Recreated features receive old terms

Holding terms on ML features creates pending rows that feature deletion never removes. updateMlFeatures collects deletedList but does not clear those features' tag rows. If a feature is deleted and recreated with the same name, approval finds the old pending row by its reused FQN and applies the old term to the new feature.

Delete pending rows when a feature is removed, and test deletion followed by same-name recreation.

Knowledge Base Used: Metadata entity lifecycle

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.

This one holds on 2.0. Feature tags live in the model JSON, and updateMlFeatures never deletes a removed feature's rows. Main does that in indexTagsOfAddedAndRemovedFeatures (#34816). Porting that cleanup would cover it.

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.

Got it — that tracks. If indexTagsOfAddedAndRemovedFeatures already handles the cleanup on main, porting that over would close the gap. Without it, the stale pending rows stick around and reattach when a feature with the same name comes back.

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.

Fixed in 9c2169d: updateMlFeatures now drops the rows of a feature that is gone (matched by name, pending ones included). Ported only the removal half of indexTagsOfAddedAndRemovedFeatures, since 2.0 reads feature tags from the model JSON. removingAnMlFeatureDropsTheTermHeldOnIt (fails without the fix).

.withTags(List.of(label(term)))));

assertRejected(() -> client.files().create(request), term);
org.openmetadata.schema.entity.data.File created = client.files().create(request);

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 Test skips required import

The added declaration uses org.openmetadata.schema.entity.data.File inline. The repository's Java guide requires importing classes instead of using fully qualified names in code. Import File and use its short name here 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 +160 to +166
entity.verify(
() ->
Entity.getEntityByNames(
Entity.GLOSSARY_TERM,
List.of(APPROVED.getFullyQualifiedName()),
"",
Include.NON_DELETED));

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 Tests miss wrong held terms

onlyTheNewlyAppliedTermIsLookedUp discards the guard's result and checks only a mocked internal call. The repository guide requires tests to check outcomes rather than internal calls with verify(). This test can pass even when the guard holds the wrong terms.

Assert which terms are held and which stay on the target before merging. Keep call checks secondary. The new anEditApplyingNoNewTermLooksNothingUp test follows the same call-only pattern.

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!

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.

(cherry picked from commit 7ebc479)

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.

On 2.0 the knowledge page queries are still here in KnowledgePageDAO (lines 16551, 16603 and 16659), not in a separate DAO, so listCount, listBefore and listAfter need tag_usage. + NOT_PENDING on their tagFQN condition, as main has in KnowledgeAssetDAOs. Without it, listing pages filtered by a term returns and counts a page where that term is only pending.

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.

Fixed in 9c2169d: KnowledgePageDAO listCount, listBefore and listAfter now add tag_usage. + NOT_PENDING to the tagFQN condition, as main does. listingPagesByATermSkipsPagesItIsOnlyPendingOn (fails without the fix).

…n assets/add, drop removed ML features' rows, show terms approved again in a session

- KnowledgePageDAO's list and count queries filtered by a term counted a page
  the term is only pending on. They skip pending rows like every other read.
- assets/add held an unapproved term on every target, so the pending write
  rewrote the type, reason and metadata of a label the asset already shows.
  It now holds the term only where it is new.
- updateMlFeatures never deleted a removed feature's rows, so its pending term
  passed to a later feature of the same name. They are dropped with it.
- Session consolidation rebases the original onto the version before the
  session, so a term deprecated and approved again by the same user looked
  unchanged and its held labels stayed hidden. The request's own change now
  counts as the status change.
@gitar-bot

gitar-bot Bot commented Nov 24, 2026

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

Persisting unapproved glossary labels and asynchronously publishing them on approval changes tag integrity across asset APIs; errors could expose incorrect classifications.

Holds glossary terms that are not Approved as pending tag rows instead of applying them, and replays them onto assets once approved. Resolved the issue where assets/add with an unapproved term rewrote an already-shown label. No open issues found.

✅ 1 closed
✅ Edge Case: assets/add with unapproved term rewrites an already-shown label

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/GlossaryTermRepository.java:1255-1269 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java:8085-8099
TermAssignment.write sends a non-Approved term to storePendingGlossaryTerms for every asset. It never checks whether the target already shows that term. The usual case is a term applied while it was Approved and later Deprecated or moved back to review. When that happens, applyTagsBatchInternal hits the existing shown row through its ON DUPLICATE KEY / ON CONFLICT upsert. That upsert keeps the row's state, but it also writes over labelType, reason and metadata with the new MANUAL label, which has no reason or metadata. An AUTOMATED or SUGGESTED label the asset already shows is therefore quietly changed. The same overwrite happens when an existing pending row's original label type and metadata are replaced. The fix is to skip the held write when targetTags already applies the term. Another option is to send it through heldTermHashesByTarget, as every other write path does, so a target that already holds the term is left alone.

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

@yan-3005
yan-3005 merged commit 9e80529 into 2.0 Nov 24, 2026
92 of 96 checks passed
@yan-3005
yan-3005 deleted the backport/2.0-37164-pending-glossary-terms branch November 24, 2026 12:34
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.

3 participants