FIX CL-#1427 - PATCH applies inherited owners (#20759)

* FIX CL-#1427 - PATCH applies inherited owners

* FIX CL-#1427 - PATCH applies inherited owners

* format
This commit is contained in:
Pere Miquel Brull 2025-04-13 06:56:33 +02:00 committed by GitHub
parent 6dac3550ba
commit c38209c63b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 1 deletions

View File

@ -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

View File

@ -2491,6 +2491,11 @@ public abstract class EntityRepository<T extends EntityInterface> {
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<EntityReference> refs = validateOwners(owners);
if (nullOrEmpty(refs)) {