Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Only Approved glossary terms can be newly applied to an asset

- **Status:** Accepted
- **Revisions:** v1 2026-11-06 (initial)
- **Revisions:** v1 2026-11-06 (initial) · v3 2026-11-19 (a term that is not Approved is kept
as pending instead of refused, and shown when it is approved)
- **Deciders:** Ram Narayan Balaji
- **Guard:** `GlossaryTermApprovedTaggingIT`, `ApprovedGlossaryTermGuardTest`
- **Related:** open-metadata/OpenMetadata#37164, open-metadata/OpenMetadata#37256
Expand Down Expand Up @@ -47,3 +48,49 @@ client applied the term. CSV import already rejected a non-Approved term on ever
- CSV import keeps its stricter per-row check, which also rejects a non-Approved term the asset
already holds. So does a term's `assets/add`: it exists only to apply the term, so a term that is
not Approved is rejected for every asset in the request, whether or not one already holds it.

## Amendment — a term that is not Approved is kept as pending, and shown once it is approved

This replaces the refusal in the initial decision. On 2.0 there is no v2: the approval gate
it amends is not part of this branch. Customers that sync glossary terms
onto assets from their own systems apply a term as soon as they create it, before a reviewer
approves it. A 400 broke those syncs, and nothing applied the term once it was approved, so each
sync would have had to watch for approvals and run again.

A write that newly applies a term that is not Approved now succeeds. The term is taken out of the
write, so it is not in the entity's answer, its change description, its search document or its
cache, and it is stored in `tag_usage` with the `state` value 2. Pending is a storage state only
the tag DAO knows (`TagUsageDAO.PENDING_STATE`), one past the public `TagLabel.State` values, so no
client can send or receive it. Every tag read
leaves pending rows out (`TagUsageDAO.NOT_PENDING`): entity and column reads, the list API's tag
filter, tag and term usage counts. No table or join is added.
Because a pending row is an ordinary `tag_usage` row, renames, moves and deletes of the asset, its
fields or the term already carry it. Writes that clear an asset's tags to write them again (CSV
import, data model, bulk re-store) keep pending rows. A client never sees a pending term, so no
write of the asset's labels removes one, by any user: a pending term leaves an asset only when the
term is removed from it through the term's `assets/remove`, or when the term is rejected.
`assets/remove` drops the term's pending labels on the asset, as it drops its shown ones, under
the same authorization. `GET
/v1/glossaryTerms/{id}/pendingAssets` lists the assets a term is pending on, paged by an `after`
cursor over target FQN hashes, leaving out assets the caller may not view.

When the term moves to Approved, after the term is stored (`GlossaryTermRepository.postUpdate`, so
a bulk update's status change is acted on only once it is saved), `GlossaryTermPendingLabels` adds
the term to each asset holding pending labels, in batches of 500 targets, as an ordinary PATCH by
the governance bot. The asset therefore records a version and a change event, and its cache,
search document and RDF are updated by the same pipeline as any edit; a document that fails to
index goes on the search retry queue. The PATCH's upsert turns the pending rows into shown ones: an
automated label, as ingestion sends, comes back Suggested, any other Confirmed, and `appliedBy`
keeps the user who applied it. A PATCH the pipeline refuses, as when the term would be mutually
exclusive with a tag the asset shows, leaves the asset's labels pending. When the term is
rejected, its pending rows are deleted.

Pending labels of an Approved term are shown again whenever they are found. An asset whose edit
fails is retried, up to three times. A write that held a term checks the term once the write commits, so a
term approved while the write ran is not missed. The server sweeps for them when it starts, so a
restart does not leave them hidden.

dbt no longer skips a term
that is not Approved (#37256); the server holds it. CSV import, of entities and of columns, keeps
its per-row refusal. Labels a
term already had before this change are left as they are.
12 changes: 7 additions & 5 deletions ingestion/src/metadata/utils/tag_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ def get_tag_label(

# Check if the tag exists
tag = metadata.get_by_name(entity=tag_type, fqn=tag_fqn)
# Only Approved glossary terms may be applied to assets, matching the server's CSV import rule.
if tag_type == GlossaryTerm and tag and tag.entityStatus != EntityStatus.Approved:
status = tag.entityStatus.value if tag.entityStatus else "missing a status"
logger.warning("Glossary term '%s' is %s, not Approved. Skipping it.", tag_fqn, status)
return None
# The server keeps a newly applied term that is not Approved hidden until it is approved.
if tag_type == GlossaryTerm and tag and tag.entityStatus not in (None, EntityStatus.Approved):
logger.info(
"Glossary term '%s' is %s, not Approved. It will show on the asset once it is approved.",
tag_fqn,
tag.entityStatus.value,
)
if tag:
return TagLabel(
tagFQN=TagFQN(tag_fqn),
Expand Down
54 changes: 1 addition & 53 deletions ingestion/tests/unit/test_dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

from metadata.generated.schema.entity.data.apiEndpoint import APIEndpoint
from metadata.generated.schema.entity.data.dashboard import Dashboard
from metadata.generated.schema.entity.data.glossaryTerm import GlossaryTerm
from metadata.generated.schema.entity.data.metric import Language
from metadata.generated.schema.entity.data.mlmodel import MlModel
from metadata.generated.schema.entity.data.table import Column, DataModel, DataType, Table
Expand All @@ -35,7 +34,6 @@
from metadata.generated.schema.type import entityReference
from metadata.generated.schema.type.entityReference import EntityReference
from metadata.generated.schema.type.entityReferenceList import EntityReferenceList
from metadata.generated.schema.type.status import EntityStatus
from metadata.generated.schema.type.tagLabel import (
LabelType,
State,
Expand Down Expand Up @@ -74,7 +72,7 @@
from metadata.ingestion.source.database.dbt.metadata import DbtSource
from metadata.ingestion.source.database.dbt.models import DbtFiles, DbtObjects, UpstreamNode
from metadata.utils.logger import ingestion_logger, set_loggers_level
from metadata.utils.tag_utils import get_tag_label, get_tag_labels
from metadata.utils.tag_utils import get_tag_labels
from metadata.utils.time_utils import datetime_to_timestamp

logger = ingestion_logger()
Expand Down Expand Up @@ -1561,56 +1559,6 @@ def test_parse_data_model_columns_bad_tag_does_not_drop_column(self, mock_fqn):
assert len(columns) == 1
assert columns[0].tags == []

def _glossary_terms_by_status(self):
"""FQN -> GlossaryTerm for every status and for no status, plus one FQN the server does not know"""
terms = {
f"Gloss.{name}": GlossaryTerm(
id=uuid.uuid4(),
name=name,
fullyQualifiedName=f"Gloss.{name}",
description="term",
glossary=EntityReference(id=uuid.uuid4(), type="glossary"),
entityStatus=status,
)
for name, status in [*((status.name, status) for status in EntityStatus), ("NoStatus", None)]
}
return terms, [*terms, "Gloss.Missing"]

def _glossary_labels(self, tags):
return [tag.tagFQN.root for tag in tags if tag.source == TagSource.Glossary]

def test_dbt_table_meta_glossary_applies_only_approved_terms(self):
terms, fqns = self._glossary_terms_by_status()
get_tag_label.cache_clear()
with patch.object(self.dbt_source_obj.metadata, "get_by_name", side_effect=lambda entity, fqn: terms.get(fqn)):
result = self.dbt_source_obj.process_dbt_meta(
manifest_meta={"openmetadata": {"glossary": fqns}},
table_fqn="svc.db.schema.table",
)
get_tag_label.cache_clear()

assert self._glossary_labels(result) == ["Gloss.Approved"]

def test_dbt_column_meta_glossary_applies_only_approved_terms(self):
terms, fqns = self._glossary_terms_by_status()
manifest_column = SimpleNamespace(
name="col",
tags=[],
meta={"openmetadata": {"glossary": fqns}},
description="kept",
data_type="varchar",
)
get_tag_label.cache_clear()
with patch.object(self.dbt_source_obj.metadata, "get_by_name", side_effect=lambda entity, fqn: terms.get(fqn)):
columns = self.dbt_source_obj.parse_data_model_columns(
manifest_node=SimpleNamespace(columns={"col": manifest_column}), catalog_node=None
)
get_tag_label.cache_clear()

assert len(columns) == 1
assert columns[0].description.root == "kept"
assert self._glossary_labels(columns[0].tags) == ["Gloss.Approved"]

@patch("metadata.ingestion.source.database.dbt.metadata.fqn")
def test_parse_data_model_columns_skips_split_when_include_tags_false(self, mock_fqn):
"""fqn.split must not be called for meta.openmetadata.tags when includeTags=False"""
Expand Down
38 changes: 38 additions & 0 deletions ingestion/tests/unit/utils/test_tag_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
Test tag_utils module
"""

import logging
import uuid
from unittest import TestCase
from unittest.mock import MagicMock

import pytest

from metadata.generated.schema.entity.data.glossaryTerm import GlossaryTerm
from metadata.generated.schema.type.entityReference import EntityReference
from metadata.generated.schema.type.status import EntityStatus
from metadata.generated.schema.type.tagLabel import TagSource
from metadata.utils.tag_utils import (
get_ometa_tag_and_classification,
get_tag_label,
Expand Down Expand Up @@ -183,3 +191,33 @@ def test_get_tag_label_filters_empty_tags(self):
classification_name="test_class",
)
self.assertIsNone(result, "get_tag_label should return None for None tag_name")


@pytest.mark.parametrize("status", [*EntityStatus, None])
def test_get_tag_label_sends_glossary_term_of_any_status(status, caplog):
"""The server holds a term that is not Approved until approval, so the client sends it and logs why it won't show yet"""
term = GlossaryTerm(
id=uuid.uuid4(),
name="Term",
fullyQualifiedName="Gloss.Term",
description="term",
glossary=EntityReference(id=uuid.uuid4(), type="glossary"),
entityStatus=status,
)
metadata = MagicMock()
metadata.get_by_name.return_value = term

get_tag_label.cache_clear()
with caplog.at_level(logging.INFO):
label = get_tag_label(metadata=metadata, tag_name="Gloss.Term", classification_name=None, tag_type=GlossaryTerm)
get_tag_label.cache_clear()

assert label.tagFQN.root == "Gloss.Term"
assert label.source == TagSource.Glossary
held_logs = [record.getMessage() for record in caplog.records if "not Approved" in record.getMessage()]
if status in (None, EntityStatus.Approved):
assert held_logs == []
else:
assert held_logs == [
f"Glossary term 'Gloss.Term' is {status.value}, not Approved. It will show on the asset once it is approved."
]
Loading
Loading