Skip to content

Fixes #37164: Reject non-Approved glossary terms when an approval workflow holds the edit - #37928

Merged
yan-3005 merged 1 commit into
mainfrom
fix/37164-approved-term-check-on-held-edit
Nov 17, 2026
Merged

yan-3005 merged 1 commit into
mainfrom
fix/37164-approved-term-check-on-held-edit

Conversation

@yan-3005

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

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #37164 (follow-up to #37643).

#37643 rejects a non-Approved glossary term when a write applies it. An approval workflow in Enforce mode holds an edit before it is written, so that check never ran for a held edit. The request answered 202 and opened a change request for a term the write would refuse. The term then landed only if someone approved the review task after the term itself was Approved.

Now ApprovalGate.stage runs the same check before it opens a change request. A held edit that newly applies a non-Approved term gets the 400 an unheld write gets, no change request is opened, and bulk PUT fails only that item.

The guard also drops terms a target already holds before it looks anything up. A write or held edit that applies no new glossary term now makes no query. Before, it looked up every glossary term on the entity once per write.

Type of change:

  • Bug fix

High-level design:

  • ApprovalGate.stage calls rejectUnapprovedGlossaryTerms beside the existing rejectMutuallyExclusiveTags. The check runs on every edit a workflow holds, not only when tags changed. A column's labels change under columns, so a workflow that gates only columns would otherwise still hold an In Review term.
  • EntityRepository.checkNewlyAppliedGlossaryTermsApproved(original, updated) is the one entry point. The gate calls it with the stored entity and the entity as it would be published (for PUT, after publishedByPut). EntityUpdater delegates to it, so the write-time check stays as the backstop.
  • ApprovedGlossaryTermGuard.rejectedTerms drops held terms in memory first, then looks up only the remaining terms in one batch, then reads tag_usage only for non-Approved terms the loaded state does not show held. Both steps only remove hashes, so the result is the same in either order.
  • ADR 2026-11-06-only-approved-glossary-terms-can-be-newly-applied-to-an-asset amended (v2).

Query cost per request:

Request Before After
Write or held edit, no glossary term on the entity 0 0
Write or held edit that keeps the terms it has 1 batch lookup of every term on the entity 0
Write or held edit adding terms 1 batch lookup of every term 1 batch lookup of the new terms only
…adding a non-Approved term the loaded state misses +1 tag_usage read +1 tag_usage read (unchanged)

A held edit is staged instead of written, so it still runs the check exactly once. No request runs it twice. Entity types no workflow gates, and edits by bots, never reach stage.

Blast radius. Every caller of ApprovalGate.stage now gets a 400, or a per-item failure, where it got a held 202 before. It does so only when the edit newly applies a non-Approved glossary term:

Path New behaviour
PATCH, PUT, column API on a held entity 400, no change request
Bulk PUT (/tables/bulk etc.) that item fails with 400; the rest go through (existing IllegalArgumentException handling)
Bulk PATCH dry-run (EntityPatchBatch.prepare) that entity fails; the rest go through (existing per-entity catch)
CSV import update of a held row same failure as the unheld row already gets
POST /changeRequests/preview/{type}/{id} 400. Used by MCP only; the UI does not call it
Glossary term move preview / admitRelations (data product ports) no new terms, so nothing changes

Not changed:

  • An already-pending change request.
  • A term demoted after its edit was held. Approving it hits the write-time check, and the request stays Pending with the reason (ChangeRequestService.flagConflicts); now covered by a test.
  • Bots.
  • 2.0 has no ApprovalGate, so it can't hold an edit; it gets only the lookup change.

Tests:

Unit tests

  • ApprovedGlossaryTermGuardTest: added anEditApplyingNoNewTermLooksNothingUp (no term lookup, no tag_usage read) and onlyTheNewlyAppliedTermIsLookedUp.
  • Local run: GovernanceApprovalRegistryTest, NativeOntologyChangeSetTest, ApprovedGlossaryTermGuardTest, TagLabelUtilTest, ChangeRequestServiceTest, ApprovalGateBulkResponseTest, ColumnRepository*Test, EntityRepository*Test: 318 run, 0 failures.

Backend integration tests

  • Added ChangeRequestUnapprovedTermIT (7 cases, owned by ChangeRequest*IT in the impact map):
    • held PATCH / PUT / column edit (workflow gating only columns) with a non-Approved term → 400, no change request, nothing published
    • held bulk PUT → only that item fails, nothing pending
    • Approved term → still held (202)
    • edit keeping a term deprecated after it was applied → still held
    • term deprecated after the edit was held, then approved → request stays Pending with the not-Approved reason, nothing published
  • Fails on main: with the three service files reverted, 7 run, 4 failures: the four rejection cases answer 202 / numberOfRowsPendingApproval: 1.
  • Local, MySQL + Elasticsearch, parallel lane, on this branch: ChangeRequestUnapprovedTermIT 7/0, ChangeRequestAdmissionIT 23/0, ChangeRequestApplyIT 11/0, ChangeRequestImportAndBulkIT 10/0, GlossaryTermApprovedTaggingIT 19/0. 70 run, 0 failures.

Ingestion integration tests

  • Not applicable.

Playwright (UI) tests

  • Not applicable: no UI change, and the UI does not call the preview endpoint.

Manual testing performed

Repro before the fix (API only, a server built from main plus the guard): an Enforce workflow on table gating tags, and a term created In Review. A human admin attached the term to the table: 202, change request Pending, table unchanged. Approving the term did not publish the edit; it waited for the review task.

UI screen recording:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added a test that covers the exact scenario we are fixing.
  • Decision check: amends docs/decisions/2026-11-06-only-approved-glossary-terms-can-be-newly-applied-to-an-asset.md (v2).

Backports: 2.1 (full fix); 2.0 (lookup change only, since 2.0 has no approval gate).

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Checks newly applied glossary terms before an approval workflow opens a change request.

  • Held asset edits reject newly applied terms that are not Approved.
  • Glossary checks look up only terms an edit newly adds.

No actionable issues were found. Tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Prepared edit] --> B{Workflow holds edit?}
  B -->|Yes| C[Check newly applied glossary terms]
  C --> D{All new terms Approved?}
  D -->|No| E[Return 400 without a change request]
  D -->|Yes| F[Open change request]
  F --> G[Reviewer approves]
  G --> H[Write-time glossary check]
  B -->|No| H
  H --> I[Publish if valid]
Loading

Reviews (1) · Last reviewed commit: "Fixes #37164: Reject non-Approved glossa..." · Reviewed by Greptile

…kflow holds the edit

An Enforce approval workflow holds an edit before it is written, so the
write-time Approved-term check never ran: the request answered 202 and opened
a change request for a term the write would refuse. ApprovalGate.stage now
runs the same check before it opens a change request, so a held edit gets the
same 400 an unheld write gets, and bulk PUT fails only that item.

The guard now drops terms a target already holds before looking terms up, so
a write or held edit that applies no new glossary term makes no query.
@yan-3005
yan-3005 requested a review from a team as a code owner November 17, 2026 02:13
@yan-3005
yan-3005 requested a review from manerow November 17, 2026 02:13
@yan-3005 yan-3005 added the To release Will cherry-pick this PR into the release branch label Nov 17, 2026
Copilot AI balanced review requested due to automatic review settings November 17, 2026 02:13

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@gitar-bot

gitar-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Pre-stage validation rejects held edits that add non-Approved glossary terms, so those edits cannot enter approval queues and callers may receive 400 responses.

Closes the gap where a held glossary edit applying a non-Approved term returned 202 and opened a change request. ApprovalGate.stage now runs the same Approved-term check as an unheld write, so such edits fail with 400 and no change request is opened, and the term lookup now runs only for newly applied terms. 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

@yan-3005
yan-3005 enabled auto-merge (squash) November 17, 2026 02:35
@yan-3005
yan-3005 merged commit 856ab56 into main Nov 17, 2026
54 checks passed
@yan-3005
yan-3005 deleted the fix/37164-approved-term-check-on-held-edit branch November 17, 2026 04:32
@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

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

Backport aborted: PR #37928 does not apply to 2.0

What the source PR fixes

PR #37928 (merge commit 856ab56cd75aa529a85e8eeb0e098aba57b14d6e) fixes a bug in
ApprovalGate.stage: when an Enforce approval workflow holds an edit before it
is written, the write-time "only Approved glossary terms may be newly applied" check
never ran, so the request answered 202 and opened a change request for a term the
write would have refused. The fix adds rejectUnapprovedGlossaryTerms(...) to
ApprovalGate.stage, so the same check runs before a change request is opened.

Why this cannot be backported to 2.0

The whole subsystem the fix lives in does not exist on 2.0:

  • org.openmetadata.service.governance.approval.ApprovalGate — the class the PR
    patches — is not present on 2.0. git cherry-pick reports it as
    "deleted by us" because the file exists at the cherry-pick's merge-base (on
    main) but was never added to 2.0; it was introduced on main after 2.0
    branched.
  • Nothing on 2.0 references ApprovalGate, GatedBy, Edited, or any of the
    "stage a gated edit before write" machinery the fix hooks into.
  • The new integration test ChangeRequestUnapprovedTermIT.java depends on
    org.openmetadata.schema.governance.changeRequest.ChangeRequest,
    ChangeRequestStatus, and a ChangeRequestITSupport test helper
    (deployHookWorkflowFor, awaitOpenApprovalTask, etc.) — none of which exist
    under openmetadata-integration-tests or openmetadata-spec on 2.0.
  • In short: on 2.0, an edit is never "held" by a governance workflow before
    being written, so the exact bug this PR fixes — a held edit bypassing the
    write-time Approved-term check — cannot occur on this branch.

What already exists on 2.0 (and is unaffected)

The write-time check itself (ApprovedGlossaryTermGuard /
EntityRepository.checkNewlyAppliedGlossaryTermsApproved) was already backported
in an earlier change (see the already-modified
docs/decisions/2026-11-06-only-approved-glossary-terms-can-be-newly-applied-to-an-asset.md
and the existing private checkNewlyAppliedGlossaryTermsApproved() method inside
EntityRepository's Updater). That part is not broken on 2.0 and needs no
change — it is only reachable from the direct-write path, which still runs the
check correctly, since there is no gating/staging path to bypass it.

The ApprovedGlossaryTermGuard.rejectedTerms lookup-ordering optimization in the
PR (drop held terms before looking up unapproved terms, instead of after) is a
real improvement, but it only exists to support ApprovalGate.stage calling the
guard on every gated write. Taking the optimization alone, detached from the
ApprovalGate caller it was written for, doesn't fix anything observable on
2.0 and isn't "this change" — so it was left out too.

State left behind

The cherry-pick (git cherry-pick -x 856ab56cd75aa529a85e8eeb0e098aba57b14d6e) is
still in progress with the original conflict markers intact in:

  • openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ApprovedGlossaryTermGuard.java
  • openmetadata-service/src/main/java/org/openmetadata/service/governance/approval/ApprovalGate.java (deleted-by-us / present only as "theirs")

No file was staged or committed. A reviewer (or the next workflow step) should
run git cherry-pick --abort to restore 2.0 to its pre-pick state.

resolver run

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.

[BUG] Enforce consistent glossary term tagging rules between API and UI

3 participants