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
4 changes: 4 additions & 0 deletions ingestion/src/metadata/ingestion/models/patch_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class PatchedEntity(BaseModel):
"reviewers": True,
# Table Entity Fields
"tableType": True,
# Source-managed: the connector recomputes it every run, so the patch has to be
# able to add, replace and remove it. Omitting it here silently drops synonyms
# on every table that already exists in OpenMetadata.
"aliases": True,
"columns": {"__all__": ALLOWED_COLUMN_FIELDS},
"tableConstraints": True,
"tablePartition": True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@
import jsonpatch
from pydantic import BaseModel

from metadata.ingestion.models.patch_request import JsonPatchUpdater, build_patch
from metadata.generated.schema.entity.data.table import Table
from metadata.ingestion.models.patch_request import (
ALLOWED_COMMON_PATCH_FIELDS,
ARRAY_ENTITY_FIELDS,
RESTRICT_UPDATE_LIST,
JsonPatchUpdater,
build_patch,
)


class JsonPatchUpdaterTest(TestCase):
Expand Down Expand Up @@ -372,3 +379,62 @@ def test_no_array_entity_fields_still_works(self):

result = build_patch(source=source, destination=dest, skip_on_failure=False)
self.assertIsNotNone(result)


class TestBuildPatchTableAliases:
"""Table.aliases has to survive the allow-listed patch the sink actually sends.

`metadata_rest.patch_entity` passes ALLOWED_COMMON_PATCH_FIELDS, and `build_patch`
diffs the models through `include=allowed_fields`. A field missing from that list
can never produce an operation, so a connector that recomputes aliases every run
would silently drop them on every table that already exists in OpenMetadata.
"""

@staticmethod
def _table(aliases):
return Table(
id=str(uuid.uuid4()),
name="orders",
columns=[],
fullyQualifiedName="svc.db.schema.orders",
aliases=aliases,
)

def _patch_ops(self, source_aliases, destination_aliases):
"""Diff two alias states through the exact call the sink makes."""
result = build_patch(
source=self._table(source_aliases),
destination=self._table(destination_aliases),
allowed_fields=ALLOWED_COMMON_PATCH_FIELDS,
restrict_update_fields=RESTRICT_UPDATE_LIST,
array_entity_fields=ARRAY_ENTITY_FIELDS,
skip_on_failure=False,
)

return result.patch if result else []

def test_aliases_are_patchable(self):
"""The allow-list carries aliases at all."""
assert "aliases" in ALLOWED_COMMON_PATCH_FIELDS

def test_first_alias_is_added(self):
assert self._patch_ops(None, ["svc.db.schema.orders_syn"]) == [
{"op": "add", "path": "/aliases", "value": ["svc.db.schema.orders_syn"]}
]

def test_further_alias_is_added(self):
ops = self._patch_ops(
["svc.db.schema.orders_syn"],
["svc.db.schema.orders_syn", "svc.db.reporting.orders_v"],
)

assert ops == [{"op": "add", "path": "/aliases/1", "value": "svc.db.reporting.orders_v"}]

def test_dropped_alias_is_removed(self):
"""Aliases are source-managed: dropping the synonym has to clear the field."""
ops = self._patch_ops(["svc.db.schema.orders_syn"], None)

assert ops == [{"op": "remove", "path": "/aliases"}]

def test_unchanged_aliases_produce_no_operation(self):
assert self._patch_ops(["svc.db.schema.orders_syn"], ["svc.db.schema.orders_syn"]) == []
Loading