Repository navigation
[2.1] Fixes #37164: Hold glossary terms that are not Approved as pending until approved - #38511
Conversation
…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)
|
🤖 This backport will not merge itself: |
| 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); |
There was a problem hiding this comment.
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.
| "SELECT targetFQNHash, labelType, reason, metadata FROM tag_usage WHERE source = :source AND tagFQNHash = :tagFQNHash " | ||
| + "AND state = " | ||
| + PENDING_STATE | ||
| + " AND targetFQNHash IN (<targetFQNHashes>)") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
|
Merged the latest Conflict: Verified on the merged 2.1 code (MySQL + Elasticsearch):
|
…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)
|
Added the same-session deprecate-then-approve fix from #38589 ( |
Automated backport of #38239 to
2.1.fb4731f0adbab92df9d80236735bb1bd95014ba2Resolution notes
Backport notes: #38239 → 2.1
Conflict
Only
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.javaconflicted, 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 withembeddings") extracted a
getWholeStoredTable(tableId)helper thataddDataModelonmain now calls to fetch the table row. That helper does not exist on
2.1— the branchstill 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 inlineget(...)call (its existing shape) and applied PR #38239's actualchange on top of it:
addDataModelgained theString updatedByparameter (already expected byTableResource.addDataModel, which came in pre-staged from the merge and callsrepository.addDataModel(id, dataModel, securityContext.getUserPrincipal().getName())).ApprovedGlossaryTermGuard.checkNewlyApplied(...)call (which rejected thewrite with a 400) was replaced with
List<HeldTerm> heldTerms = holdUnapprovedModelTerms(table, dataModel);, andstorePendingGlossaryTerms(heldTerms, updatedBy)was added afterdao.update(...),matching the rest of the PR's "hold as pending instead of rejecting" behavior.
No main-only refactor (the
getWholeStoredTableextraction) was pulled into2.1; onlythe glossary-term-holding behavior from #38239 was ported.
What to check by hand
addDataModelon2.1now reads: inlineget(...)→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, andstorePendingGlossaryTermsall pre-existedon this branch from the clean parts of the cherry-pick (in
ApprovedGlossaryTermGuardand
EntityRepository) — nothing new was introduced to resolve this conflict.TableRepository.javastill unmerged in theindex; 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
Fix the approval/removal race and satisfy the repository's comment rule before merging.
Findings
Summary
Writes now keep newly applied, unapproved glossary terms hidden in
tag_usageuntil approval.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]Reviews (1) · Last reviewed commit: "Fixes #37164: Hold glossary terms that a..." · Reviewed by Greptile