Skip to content

[2.1] Fixes #37164: Only Approved glossary terms can be applied through the API - #37688

Merged
yan-3005 merged 1 commit into
2.1from
backport/2.1/pr-37643
Nov 12, 2026
Merged

yan-3005 merged 1 commit into
2.1from
backport/2.1/pr-37643

Conversation

@yan-3005

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #37164

Backport of #37643 to 2.1. It's a clean cherry-pick of squash commit 98033981f8, with no conflicts.

The API now rejects, with a 400, any write that newly applies a glossary term that is not Approved, the same rule the UI already enforces. It covers create, PUT, PATCH, bulk PUT, createMany, a glossary term's assets/add, the column APIs and their dry-run previews, and the table dataModel (dbt) endpoint. A term that leaves Approved after it was applied stays on the asset, and writes that re-send it still pass. See #37643 for the design and docs/decisions/2026-11-06-only-approved-glossary-terms-can-be-newly-applied-to-an-asset.md.

dbt's client-side skip of non-Approved terms is tracked in #37256 and should ship in the same release.

Type of change:

  • Bug fix

Tests:

Run locally on this branch (MySQL + Elasticsearch):

  • Unit tests: ApprovedGlossaryTermGuardTest, TagLabelUtilTest and ColumnRepositoryImportTest. 46 run, 0 failures.
  • GlossaryTermApprovedTaggingIT: 19 run, 0 failures.

The full IT and Playwright evidence is on #37643.

Checklist:

  • My PR title is [2.1] Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have added tests and listed them above.

🤖 Generated with Claude Code

… API (#37643)

* Fixes #37164: Only Approved glossary terms can be applied through the API

The UI only offers Approved glossary terms when tagging an asset, but the
API accepted Draft, In Review, Rejected and Deprecated terms on every write
path. ApprovedGlossaryTermGuard now rejects, per target (asset or inline
field), any glossary term that is newly applied and not Approved: on create,
PUT, PATCH, bulk PUT, the table dataModel, a term's assets/add, the column
API, and the column bulk-update / CSV previews. A term already held on the
same target stays, so writes that carry it back still pass.

* Judge bulk creates per input and match moved fields by name path

createMany runs the glossary-term guard in BulkEntityCreator.prepare so a
rejected input fails alone instead of failing the request. The updater
keys the updated entity's targets by the stored FQN of the same name path,
so a container move that rewrites its data-model column FQNs before the
stored labels are re-keyed does not make a held term look new. Adds tests
for both and for the column bulk-update and CSV dry-run previews.

* Find tagged fields per repository and compare terms by hash

The guard took nested fields from ChildFieldResolver, which leaves File
columns out, and keyed name paths by field name alone, so a request and a
response field with the same name collided. Fields now come from
EntityRepository.taggedFieldContainers (FileRepository adds its columns),
name paths carry the container path and ignore case like column matching,
and terms are compared by FQN hash so a quoted FQN cannot slip past.

* Keep IT fixture names short and record the ingestion decision

The createMany test case's suite is named after its table, so the table
now lives under a short service and schema. The container move test reads
back with tags. The decision record notes that bots get no exemption and
that dbt skips non-Approved terms client-side (#37256), shipping together.

* Test the bulk PUT update rejection and document assets/add

Adds the IT step for a bulk PUT that adds a Deprecated term to an existing
table. assets/add rejects a non-Approved term for every asset in the
request, as the endpoint only applies terms; the Javadoc and ADR now say so.

* Approve the moved term before tagging it in the move-rewrite IT

test_approvedGlossaryTermMoveRewritesTaggedAssetsInSearch tagged a table
with a term still In Review, which is now refused. The test approves the
term through its own approval task first; the aboutEntity filter matches
by FQN prefix, so the task is picked by the term's id, not the first one.

* Judge a column CSV dry-run in one guard call

The dry-run called the approved-term guard once per row, so a file with
many glossary-tagged rows looked terms up row by row on the request thread.
It now pools every row's labels per column, runs the guard once for the
file, and judges each row by its own terms against the shared result.

(cherry picked from commit 9803398)
@yan-3005
yan-3005 requested a review from a team as a code owner November 12, 2026 13:53
@yan-3005
yan-3005 requested review from harshach and removed request for a team November 12, 2026 13:53
@yan-3005 yan-3005 added safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch labels Nov 12, 2026
@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 +1077 to +1078
Map<String, Set<String>> previewRejections =
dryRun ? previewRejections(parsedRows, occurrencesByName) : Map.of();

@gitar-bot gitar-bot Bot Nov 12, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Edge Case: One malformed term FQN aborts the whole CSV dry run

previewRejections runs once, before the per-row loop and outside its try/catch. It hands every row's glossary-term FQNs to ApprovedGlossaryTermGuard.rejectedTermHashesByTarget. That path hashes each requested FQN (termHash → FullyQualifiedName.buildHash, and findEntityByNames hashes them again), and buildHash throws IllegalArgumentException(invalidFQN) when a value fails to parse, for example Glossary."Bad. So one row with a malformed term makes the whole dry-run import fail with an error. The real import (dryRun=false) handles the same row inside the per-row try/catch and only that row fails. The preview then no longer matches the apply, which the ADR and the method's Javadoc say it should, and before this PR the same file previewed fine. Fix: hash each row's terms on their own and leave out (and count as failed) the rows whose FQNs do not parse, before the single guard call.

Leave rows whose term FQNs do not parse out of the pooled guard call; the per-row loop then fails them the way the apply would.:

for (String[] fields : parsedRows) {
  List<TagLabel> tags = rowTags(fields);
  if (!hasParseableTermFqns(tags)) {
    continue;
  }
  for (ColumnOccurrence occurrence : listOrEmpty(occurrencesByName.get(fields[0]))) {
    tagsByColumn
        .computeIfAbsent(occurrence.getColumnFQN(), column -> new ArrayList<>())
        .addAll(tags);
  }
}

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 🟡 Medium risk 0 closed / 1 findings

Enforcing Approved-only glossary tagging across asset and column APIs could cause ingestion writes that newly apply non-approved terms to fail.

Backports the approved-only glossary term guard to 2.1 so the API rejects newly applied non-Approved terms with a 400, matching the UI rule while keeping previously applied terms and re-sent writes working. Approved with suggestions: a malformed term FQN in one CSV row makes the whole dry-run preview in ColumnRepository.previewRejections fail instead of only that row, so the preview diverges from the real import. Hashing each row's terms separately and counting unparseable rows as failed before the single guard call would resolve it.

💡 Edge Case: One malformed term FQN aborts the whole CSV dry run

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ColumnRepository.java:1077-1078 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ColumnRepository.java:1128-1142 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ApprovedGlossaryTermGuard.java:146-160 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ApprovedGlossaryTermGuard.java:225-227

previewRejections runs once, before the per-row loop and outside its try/catch. It hands every row's glossary-term FQNs to ApprovedGlossaryTermGuard.rejectedTermHashesByTarget. That path hashes each requested FQN (termHash → FullyQualifiedName.buildHash, and findEntityByNames hashes them again), and buildHash throws IllegalArgumentException(invalidFQN) when a value fails to parse, for example Glossary."Bad. So one row with a malformed term makes the whole dry-run import fail with an error. The real import (dryRun=false) handles the same row inside the per-row try/catch and only that row fails. The preview then no longer matches the apply, which the ADR and the method's Javadoc say it should, and before this PR the same file previewed fine. Fix: hash each row's terms on their own and leave out (and count as failed) the rows whose FQNs do not parse, before the single guard call.

Leave rows whose term FQNs do not parse out of the pooled guard call; the per-row loop then fails them the way the apply would.
for (String[] fields : parsedRows) {
  List<TagLabel> tags = rowTags(fields);
  if (!hasParseableTermFqns(tags)) {
    continue;
  }
  for (ColumnOccurrence occurrence : listOrEmpty(occurrencesByName.get(fields[0]))) {
    tagsByColumn
        .computeIfAbsent(occurrence.getColumnFQN(), column -> new ArrayList<>())
        .addAll(tags);
  }
}
🤖 Prompt for agents
Code Review: Backports the approved-only glossary term guard to 2.1 so the API rejects newly applied non-Approved terms with a 400, matching the UI rule while keeping previously applied terms and re-sent writes working. Approved with suggestions: a malformed term FQN in one CSV row makes the whole dry-run preview in `ColumnRepository.previewRejections` fail instead of only that row, so the preview diverges from the real import. Hashing each row's terms separately and counting unparseable rows as failed before the single guard call would resolve it.

1. 💡 Edge Case: One malformed term FQN aborts the whole CSV dry run
   Files: openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ColumnRepository.java:1077-1078, openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ColumnRepository.java:1128-1142, openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ApprovedGlossaryTermGuard.java:146-160, openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/ApprovedGlossaryTermGuard.java:225-227

   `previewRejections` runs once, before the per-row loop and outside its `try/catch`. It hands every row's glossary-term FQNs to `ApprovedGlossaryTermGuard.rejectedTermHashesByTarget`. That path hashes each requested FQN (`termHash` → `FullyQualifiedName.buildHash`, and `findEntityByNames` hashes them again), and `buildHash` throws `IllegalArgumentException(invalidFQN)` when a value fails to parse, for example `Glossary."Bad`. So one row with a malformed term makes the whole dry-run import fail with an error. The real import (`dryRun=false`) handles the same row inside the per-row `try/catch` and only that row fails. The preview then no longer matches the apply, which the ADR and the method's Javadoc say it should, and before this PR the same file previewed fine. Fix: hash each row's terms on their own and leave out (and count as failed) the rows whose FQNs do not parse, before the single guard call.

   Fix (Leave rows whose term FQNs do not parse out of the pooled guard call; the per-row loop then fails them the way the apply would.):
   for (String[] fields : parsedRows) {
     List<TagLabel> tags = rowTags(fields);
     if (!hasParseableTermFqns(tags)) {
       continue;
     }
     for (ColumnOccurrence occurrence : listOrEmpty(occurrencesByName.get(fields[0]))) {
       tagsByColumn
           .computeIfAbsent(occurrence.getColumnFQN(), column -> new ArrayList<>())
           .addAll(tags);
     }
   }

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 682a630 into 2.1 Nov 12, 2026
56 of 58 checks passed
@yan-3005
yan-3005 deleted the backport/2.1/pr-37643 branch November 12, 2026 14:34
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 To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants