From c38209c63b1e54b61f89d3b3a73d3ed417eb0af6 Mon Sep 17 00:00:00 2001 From: Pere Miquel Brull Date: Sun, 13 Apr 2025 06:56:33 +0200 Subject: [PATCH] FIX CL-#1427 - PATCH applies inherited owners (#20759) * FIX CL-#1427 - PATCH applies inherited owners * FIX CL-#1427 - PATCH applies inherited owners * format --- .../integration/ometa/test_ometa_patch.py | 43 ++++++++++++++++++- .../service/jdbi3/EntityRepository.java | 5 +++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ingestion/tests/integration/ometa/test_ometa_patch.py b/ingestion/tests/integration/ometa/test_ometa_patch.py index d37ad317474..98c1882b391 100644 --- a/ingestion/tests/integration/ometa/test_ometa_patch.py +++ b/ingestion/tests/integration/ometa/test_ometa_patch.py @@ -252,7 +252,7 @@ class OMetaTableTest(TestCase): ) def test_patch_table(self): - new_patched_table = self.patch_test_table.copy(deep=True) + new_patched_table = self.patch_test_table.model_copy(deep=True) # Test adding a new column to the table new_patched_table.columns.append( @@ -640,3 +640,44 @@ class OMetaTableTest(TestCase): with_description.columns[2].children[1].description.root, "I am so nested", ) + + def test_patch_when_inherited_owner(self): + """PATCHing anything when owner is inherited, does not add the owner to the entity""" + + # Prepare a schema with owners + create_schema = get_create_entity( + entity=DatabaseSchema, reference=self.db_entity.fullyQualifiedName + ) + create_schema.owners = self.owner_team_1 + db_schema_entity = self.metadata.create_or_update(data=create_schema) + + # Add a table and check it has inherited owners + create_table = get_create_entity( + entity=Table, reference=db_schema_entity.fullyQualifiedName + ) + _table = self.metadata.create_or_update(data=create_table) + + table: Table = self.metadata.get_by_name( + entity=Table, fqn=_table.fullyQualifiedName, fields=["owners"] + ) + assert table.owners.root + assert table.owners.root[0].inherited + + # Add a description to the table and PATCH it + dest = table.model_copy(deep=True) + dest.description = Markdown(root="potato") + + self.metadata.patch( + entity=Table, + source=table, + destination=dest, + ) + + patched_table = self.metadata.get_by_name( + entity=Table, fqn=table.fullyQualifiedName, fields=["owners"] + ) + + # Check the table still has inherited owners + assert patched_table.description.root == "potato" + assert patched_table.owners.root + assert patched_table.owners.root[0].inherited diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java index 1359ebfe59d..124f67f85de 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java @@ -2491,6 +2491,11 @@ public abstract class EntityRepository { if (nullOrEmpty(owners)) { return owners; } + // Check if owners are inherited. If so, ignore the validation + if (owners.stream().allMatch(owner -> owner.getInherited() != null && owner.getInherited())) { + return owners; + } + // populate owner entityRefs with all fields List refs = validateOwners(owners); if (nullOrEmpty(refs)) {