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
Expand Up @@ -5341,22 +5341,19 @@ void test_singleEntityPut_displayNameAllowedBot_updatesDisplayName(TestNamespace
}

/**
* Test: A bot whose policy does NOT deny {@code EditOwners} (the ingestion bot - {@code
* IngestionBotPolicy}/{@code DefaultBotPolicy} carry only a {@code DisplayName-Deny}) CAN reassign
* owners through a single-entity PUT even when an owner already exists.
* Test: A bot single-entity PUT carrying owners must not replace the owners a user assigned.
*
* <p>Regression guard for the over-broad guard that reverted owners on <em>any</em> bot PUT once
* an owner was set, which silently broke ingestion ownership re-sync. {@code
* EntityRepository#updateOwners} now keys on the same policy-aware {@code updatingBotDeniedOperation
* (EDIT_OWNERS)} check as {@code updateDisplayName}, so a policy-allowed bot updates owners while a
* denied bot (or {@code overrideMetadata=false} with a field-deny) still preserves them.
* <p>No shipped bot policy denies {@code EditOwners}, so a policy-keyed guard never fired and
* owners sent by ingestion ({@code ownerConfig}, {@code includeOwners}) replaced user-assigned
* ones on every re-sync. A bot PUT now only fills owners on an entity that has none; a PATCH or
* a bulk run with {@code overrideMetadata=true} still reassigns them.
*/
@Test
void test_singleEntityPut_bot_updatesOwnersWhenPolicyAllows(TestNamespace ns) {
void test_singleEntityPut_bot_preservesUserOwners(TestNamespace ns) {
if (!supportsBulkAPI || !supportsOwners) return;
if (!hasField("setOwners", List.class)) return;

K request = createRequest(ns.prefix("put_ownallow_"), ns);
K request = createRequest(ns.prefix("put_ownkeep_"), ns);
T created = createEntity(request);
String fqn = created.getFullyQualifiedName();

Expand All @@ -5378,9 +5375,9 @@ void test_singleEntityPut_bot_updatesOwnersWhenPolicyAllows(TestNamespace ns) {
assertNotNull(result.getOwners(), "owners present after bot update: " + fqn);
assertFalse(result.getOwners().isEmpty(), "owners not cleared: " + fqn);
assertEquals(
shared.USER2.getId(),
shared.USER1.getId(),
result.getOwners().get(0).getId(),
"Bot allowed EditOwners (ingestion bot, no Owner-Deny) must update owners via PUT: " + fqn);
"A bot PUT must not replace user-assigned owners: " + fqn);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openmetadata.it.bootstrap.SharedEntities;
import org.openmetadata.it.factories.DatabaseSchemaTestFactory;
import org.openmetadata.it.factories.DatabaseServiceTestFactory;
import org.openmetadata.it.util.BulkApi;
Expand All @@ -22,6 +25,7 @@
import org.openmetadata.it.util.TestNamespaceExtension;
import org.openmetadata.schema.api.classification.CreateClassification;
import org.openmetadata.schema.api.classification.CreateTag;
import org.openmetadata.schema.api.data.CreateDatabaseSchema;
import org.openmetadata.schema.api.data.CreateTable;
import org.openmetadata.schema.entity.classification.Classification;
import org.openmetadata.schema.entity.classification.Tag;
Expand All @@ -31,8 +35,10 @@
import org.openmetadata.schema.type.AssetCertification;
import org.openmetadata.schema.type.Column;
import org.openmetadata.schema.type.ColumnDataType;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.TableConstraint;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.service.util.FullyQualifiedName;

/**
* Integration tests for the {@code overrideMetadata} flag on the bulk path ({@code PUT
Expand Down Expand Up @@ -309,6 +315,44 @@ void test_botReplacesMutuallyExclusiveColumnTag_withOverride(TestNamespace ns) t
tagFqns(getTable(fqn).getColumns().getFirst().getTags()));
}

@Test
void test_overrideKeepsTableTagsFromClassificationsNotSent(TestNamespace ns) throws Exception {
String schemaFqn = setupSchema(ns);
List<TagLabel> sourceTags = createMutuallyExclusiveTags(ns, "ovr_keep_table_src");
TagLabel curatedTag = createMutuallyExclusiveTags(ns, "ovr_keep_table_curated").getFirst();
CreateTable original = table(ns, schemaFqn, "ovr_keep_table", "desc", "hash-v1");
original.setTags(List.of(sourceTags.getFirst(), curatedTag));
BulkApi.upsert("tables", List.of(original), false, BulkApi.botToken());

CreateTable changed = table(ns, schemaFqn, "ovr_keep_table", "desc", "hash-v2");
changed.setTags(List.of(sourceTags.getLast()));
BulkApi.upsert("tables", List.of(changed), true, BulkApi.botToken());

String fqn = schemaFqn + "." + original.getName();
assertEquals(
Set.of(sourceTags.getLast().getTagFQN(), curatedTag.getTagFQN()),
Set.copyOf(tagFqns(getTable(fqn).getTags())));
}

@Test
void test_overrideKeepsColumnTagsFromClassificationsNotSent(TestNamespace ns) throws Exception {
String schemaFqn = setupSchema(ns);
List<TagLabel> sourceTags = createMutuallyExclusiveTags(ns, "ovr_keep_col_src");
TagLabel curatedTag = createMutuallyExclusiveTags(ns, "ovr_keep_col_curated").getFirst();
CreateTable original = table(ns, schemaFqn, "ovr_keep_col", "desc", "hash-v1");
original.getColumns().getFirst().setTags(List.of(sourceTags.getFirst(), curatedTag));
BulkApi.upsert("tables", List.of(original), false, BulkApi.botToken());

CreateTable changed = table(ns, schemaFqn, "ovr_keep_col", "desc", "hash-v2");
changed.getColumns().getFirst().setTags(List.of(sourceTags.getLast()));
BulkApi.upsert("tables", List.of(changed), true, BulkApi.botToken());

String fqn = schemaFqn + "." + original.getName();
assertEquals(
Set.of(sourceTags.getLast().getTagFQN(), curatedTag.getTagFQN()),
Set.copyOf(tagFqns(getTable(fqn).getColumns().getFirst().getTags())));
}

@Test
void test_overrideDoesNotRemoveTagsWhenNoneSupplied(TestNamespace ns) throws Exception {
String schemaFqn = setupSchema(ns);
Expand Down Expand Up @@ -392,6 +436,100 @@ private void assertConstraintsSurviveBotPutWithoutThem(
assertEquals(List.of("c1"), constraints.getFirst().getColumns());
}

@Test
void test_botKeepsUserOwners_withoutOverride(TestNamespace ns) throws Exception {
SharedEntities shared = SharedEntities.get();
assertEquals(
List.of(shared.USER1.getId()),
ownerIdsAfterSourceSendsOwner(ns, "own_keep", shared.USER1_REF, false),
"owners from the source (ownerConfig/includeOwners) must not replace a user's owners");
}

@Test
void test_botReplacesUserOwners_withOverride(TestNamespace ns) throws Exception {
SharedEntities shared = SharedEntities.get();
assertEquals(
List.of(shared.USER2.getId()),
ownerIdsAfterSourceSendsOwner(ns, "own_override", shared.USER1_REF, true),
"overrideMetadata=true lets the source's owners replace the stored ones");
}

@Test
void test_botFillsOwners_whenEntityHasNone(TestNamespace ns) throws Exception {
SharedEntities shared = SharedEntities.get();
assertEquals(
List.of(shared.USER2.getId()),
ownerIdsAfterSourceSendsOwner(ns, "own_fill", null, false),
"a source owner still lands on an entity that has none");
}

/** A user (admin) creates the table with {@code userOwner}; ingestion re-syncs it as owned by USER2. */
private List<UUID> ownerIdsAfterSourceSendsOwner(
TestNamespace ns, String baseName, EntityReference userOwner, boolean overrideMetadata)
throws Exception {
String schemaFqn = setupSchema(ns);
CreateTable curated = table(ns, schemaFqn, baseName, "desc", "hash-v1");
if (userOwner != null) {
curated.setOwners(List.of(userOwner));
}
BulkApi.upsert("tables", List.of(curated), false, SdkClients.getAdminToken());

CreateTable fromSource = table(ns, schemaFqn, baseName, "desc", "hash-v2");
fromSource.setOwners(List.of(SharedEntities.get().USER2_REF));
BulkApi.upsert("tables", List.of(fromSource), overrideMetadata, BulkApi.botToken());

return getTable(schemaFqn + "." + curated.getName()).getOwners().stream()
.map(EntityReference::getId)
.toList();
}

@Test
void test_botKeepsTableRetentionPeriod_withoutOverride(TestNamespace ns) throws Exception {
assertTableRetentionPeriodKept(ns, "ret_off", false);
}

@Test
void test_botKeepsTableRetentionPeriod_withOverride(TestNamespace ns) throws Exception {
assertTableRetentionPeriodKept(ns, "ret_on", true);
}

private void assertTableRetentionPeriodKept(
TestNamespace ns, String baseName, boolean overrideMetadata) throws Exception {
String schemaFqn = setupSchema(ns);
CreateTable curated = table(ns, schemaFqn, baseName, "desc", "hash-v1");
curated.setRetentionPeriod("P30D");
BulkApi.upsert("tables", List.of(curated), false, SdkClients.getAdminToken());

CreateTable fromSource = table(ns, schemaFqn, baseName, "desc", "hash-v2");
BulkApi.upsert("tables", List.of(fromSource), overrideMetadata, BulkApi.botToken());

assertEquals(
"P30D",
getTable(schemaFqn + "." + curated.getName()).getRetentionPeriod(),
"no source sends retentionPeriod, so a bot PUT must not blank it");
}

@Test
void test_botKeepsSchemaRetentionPeriod_withOverride(TestNamespace ns) throws Exception {
String databaseFqn = FullyQualifiedName.getParentFQN(setupSchema(ns));
CreateDatabaseSchema curated =
new CreateDatabaseSchema()
.withName(ns.prefix("ret_schema"))
.withDatabase(databaseFqn)
.withRetentionPeriod("P30D");
curated.setSourceHash("hash-v1");
BulkApi.upsert("databaseSchemas", List.of(curated), false, SdkClients.getAdminToken());

CreateDatabaseSchema fromSource =
new CreateDatabaseSchema().withName(curated.getName()).withDatabase(databaseFqn);
fromSource.setSourceHash("hash-v2");
BulkApi.upsert("databaseSchemas", List.of(fromSource), true, BulkApi.botToken());

DatabaseSchema schema =
SdkClients.adminClient().databaseSchemas().getByName(databaseFqn + "." + curated.getName());
assertEquals("P30D", schema.getRetentionPeriod());
}

private TableConstraint primaryKey(String column) {
return new TableConstraint()
.withConstraintType(TableConstraint.ConstraintType.PRIMARY_KEY)
Expand Down Expand Up @@ -466,7 +604,7 @@ private Table getTable(String fqn) throws Exception {
SdkClients.getServerUrl()
+ "/v1/tables/name/"
+ fqn
+ "?fields=columns,tags,certification,tableConstraints"))
+ "?fields=columns,tags,owners,certification,tableConstraints"))
.header("Authorization", "Bearer " + SdkClients.getAdminToken())
.GET()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,11 @@ public void entitySpecificUpdate(boolean consolidatingChanges) {
compareAndUpdate(
"retentionPeriod",
() ->
recordChange(
"retentionPeriod", original.getRetentionPeriod(), updated.getRetentionPeriod()));
updateUserOnlyField(
"retentionPeriod",
original.getRetentionPeriod(),
updated.getRetentionPeriod(),
updated::setRetentionPeriod));
compareAndUpdate(
"sourceHash",
() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,11 @@ public void entitySpecificUpdate(boolean consolidatingChanges) {
compareAndUpdate(
"retentionPeriod",
() ->
recordChange(
"retentionPeriod", original.getRetentionPeriod(), updated.getRetentionPeriod()));
updateUserOnlyField(
"retentionPeriod",
original.getRetentionPeriod(),
updated.getRetentionPeriod(),
updated::setRetentionPeriod));
compareAndUpdate(
"sourceUrl",
() -> recordChange("sourceUrl", original.getSourceUrl(), updated.getSourceUrl()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,11 @@ public void entitySpecificUpdate(boolean consolidatingChanges) {
compareAndUpdate(
"retentionPeriod",
() ->
recordChange(
"retentionPeriod", original.getRetentionPeriod(), updated.getRetentionPeriod()));
updateUserOnlyField(
"retentionPeriod",
original.getRetentionPeriod(),
updated.getRetentionPeriod(),
updated::setRetentionPeriod));
compareAndUpdate(
"sourceUrl",
() -> recordChange("sourceUrl", original.getSourceUrl(), updated.getSourceUrl()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@
@Getter protected final Set<String> allowedFields;
public final boolean supportsSoftDelete;
@Getter protected final boolean supportsTags;
@Getter protected final boolean supportsOwners;

Check warning on line 544 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / Build Integration Test Runtime

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 544 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / Build Integration Test Runtime

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 544 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / Build Integration Test Runtime

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 544 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / playwright / build

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 544 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / maven-sonarcloud-ci

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 544 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / openmetadata-service-unit-tests

Not generating isSupportsOwners(): A method with that name already exists

Check warning on line 544 in openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

View workflow job for this annotation

GitHub Actions / py-run-build-tests

Not generating isSupportsOwners(): A method with that name already exists
@Getter protected final boolean supportsStyle;
@Getter protected final boolean supportsLifeCycle;
@Getter protected final boolean supportsCertification;
Expand Down Expand Up @@ -10041,16 +10041,16 @@
}

private void updateOwners() {
// A bot whose policy denies EditOwners (e.g. the ingestion bot via DefaultBotPolicy /
// IngestionBotPolicy) must not clobber user-curated owners. A PUT or bulk update authorizes
// with the coarse EDIT_ALL operation, which does not intersect that field-level deny, so
// re-apply it here. Bots the policy allows fall through and update owners as before. A bulk
// force-sync (overrideMetadata=true) also bypasses this guard.
// A bot PUT only fills owners on an entity that has none: owners sent by ingestion
// (ownerConfig, includeOwners) must not replace the ones a user assigned, as includeOwners
// documents. This can't be left to the bot policy - no shipped bot policy denies EditOwners,
// so a policy check never fired. A PATCH, or a bulk run with overrideMetadata=true, still
// reassigns them.
boolean preserveUserOwners =
updatedByBot()
&& !nullOrEmpty(original.getOwners())
&& !overrideMetadata
&& updatingBotDeniedOperation(MetadataOperation.EDIT_OWNERS);
operation.isPut()
&& updatedByBot()
&& !nullOrEmpty(getEntityReferences(original.getOwners()))
&& !overrideMetadata;
if (preserveUserOwners) {
updated.setOwners(original.getOwners());
return;
Expand Down Expand Up @@ -10144,6 +10144,9 @@
checkMutuallyExclusive(updatedTags);
} else {
// PATCH and an explicit PUT override replace tags.
if (operation.isPut()) {
keepTagsOutsideRequestedClassifications(origTags, updatedTags);
}
// Use Set for O(1) lookup performance instead of O(n) stream().anyMatch()
List<TagLabel> persistableUpdatedTags = getNonDerivedTags(updatedTags);
Set<String> updatedTagKeys = createTagKeySet(persistableUpdatedTags);
Expand Down Expand Up @@ -10199,6 +10202,24 @@
updatedTags.sort(compareTagLabel);
}

/**
* An override run replaces tags only within the classifications and glossaries it sends. Tier,
* automator-propagated and user-applied tags from any other one are never emitted by a source,
* so their absence from the request must not delete them.
*/
private void keepTagsOutsideRequestedClassifications(
List<TagLabel> origTags, List<TagLabel> updatedTags) {
Set<String> requestedRoots =
getNonDerivedTags(updatedTags).stream()
.map(tag -> FullyQualifiedName.getRoot(tag.getTagFQN()))
.collect(Collectors.toSet());
EntityUtil.mergeTags(
updatedTags,
origTags.stream()
.filter(tag -> !requestedRoots.contains(FullyQualifiedName.getRoot(tag.getTagFQN())))
.toList());
}

protected void updateTagsForImport(
String fqn, String fieldName, List<TagLabel> origTags, List<TagLabel> updatedTags) {
// Remove current entity tags in the database. It will be added back later from the merged tag
Expand Down Expand Up @@ -10548,6 +10569,20 @@
}
}

/**
* Updates a field only users set and no connector sends, such as retentionPeriod. A bot PUT
* always omits it, so - override or not - that absence keeps the stored value instead of
* blanking it.
*/
protected final <V> void updateUserOnlyField(
String fieldName, V origValue, V updatedValue, Consumer<V> setUpdated) {
if (operation.isPut() && updatedByBot() && updatedValue == null && origValue != null) {
setUpdated.accept(origValue);
return;
}
recordChange(fieldName, origValue, updatedValue);
}

private void updateLifeCycle() {
if (!supportsLifeCycle) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2281,8 +2281,11 @@ public void entitySpecificUpdate(boolean consolidatingChanges) {
compareAndUpdate(
"retentionPeriod",
() ->
recordChange(
"retentionPeriod", original.getRetentionPeriod(), updated.getRetentionPeriod()));
updateUserOnlyField(
"retentionPeriod",
original.getRetentionPeriod(),
updated.getRetentionPeriod(),
updated::setRetentionPeriod));
compareAndUpdate(
"compressionEnabled",
() ->
Expand Down
Loading