Skip to content
Closed
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 @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -28,6 +29,7 @@
import org.openmetadata.schema.entity.services.DatabaseService;
import org.openmetadata.schema.type.Column;
import org.openmetadata.schema.type.ColumnDataType;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.schema.type.api.BulkOperationResult;

/**
Expand Down Expand Up @@ -161,6 +163,47 @@ void test_softDeletedTable_isRestored_evenWithMatchingHash(TestNamespace ns) thr
"soft-deleted table must be restored by the bulk path");
}

@Test
void test_manualPatchClearsSourceHash_soSameHashReappliesTags(TestNamespace ns) throws Exception {
String schemaFqn = setupSchema(ns);
String tagFqn = createClassificationAndTag(ns);
TagLabel tag =
new TagLabel()
.withTagFQN(tagFqn)
.withSource(TagLabel.TagSource.CLASSIFICATION)
.withLabelType(TagLabel.LabelType.MANUAL);

CreateTable original =
table(ns, schemaFqn, "fp_patch_tags", "desc", "hash-patch-tags").withTags(List.of(tag));
BulkApi.upsert("tables", List.of(original));

String fqn = tableFqn(schemaFqn, original.getName());
Table created = getTable(fqn);
assertTrue(
created.getTags() != null
&& created.getTags().stream().anyMatch(t -> tagFqn.equals(t.getTagFQN())),
"tag must be applied on create");

// Simulate a UI/automation edit that removes the tag via PATCH (out-of-band vs. ingestion).
patchTableTagsToEmpty(created.getId().toString());

Table patched = getTable(fqn);
assertTrue(
patched.getTags() == null || patched.getTags().isEmpty(),
"tag must be cleared by the manual PATCH");
assertNull(patched.getSourceHash(), "PATCH must clear the stored sourceHash");

// Re-ingest the same source content with the same sourceHash. The fast-path must NOT skip the
// entity (the stored hash was cleared above), so the source tag is re-applied.
BulkApi.upsert("tables", List.of(original));

Table after = getTable(fqn);
assertTrue(
after.getTags() != null
&& after.getTags().stream().anyMatch(t -> tagFqn.equals(t.getTagFQN())),
"tag must be re-applied on re-ingest even with a matching sourceHash");
}

// ===================================================================
// HELPERS
// ===================================================================
Expand All @@ -187,6 +230,61 @@ private String tableFqn(String schemaFqn, String tableName) {
return schemaFqn + "." + tableName;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant helper comments

The new comments above createClassificationAndTag, patchTableTagsToEmpty, and the manual patch call merely restate the self-explanatory operations, adding maintenance noise without documenting non-obvious rationale.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

/** Creates a classification + tag over raw HTTP and returns the tag's fully qualified name. */
private String createClassificationAndTag(TestNamespace ns) throws Exception {
String baseUrl = SdkClients.getServerUrl();
String adminToken = SdkClients.getAdminToken();

String clsName = ns.prefix("fp_cls");
String clsBody = "{\"name\":\"" + clsName + "\",\"description\":\"regression classification\"}";
HttpResponse<String> clsResp =
HTTP_CLIENT.send(
HttpRequest.newBuilder()
.uri(URI.create(baseUrl + "/v1/classifications"))
.header("Authorization", "Bearer " + adminToken)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(clsBody))
.build(),
HttpResponse.BodyHandlers.ofString());
assertTrue(
clsResp.statusCode() == 200 || clsResp.statusCode() == 201,
"create classification: " + clsResp.statusCode() + " " + clsResp.body());
String clsFqn = OBJECT_MAPPER.readTree(clsResp.body()).get("fullyQualifiedName").asText();

String tagBody =
"{\"name\":\"fp_tag\",\"description\":\"regression tag\",\"classification\":\""
+ clsFqn
+ "\"}";
HttpResponse<String> tagResp =
HTTP_CLIENT.send(
HttpRequest.newBuilder()
.uri(URI.create(baseUrl + "/v1/tags"))
.header("Authorization", "Bearer " + adminToken)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(tagBody))
.build(),
HttpResponse.BodyHandlers.ofString());
assertTrue(
tagResp.statusCode() == 200 || tagResp.statusCode() == 201,
"create tag: " + tagResp.statusCode() + " " + tagResp.body());
return OBJECT_MAPPER.readTree(tagResp.body()).get("fullyQualifiedName").asText();
}

/** PATCHes the table to replace its tags with an empty list (a manual, out-of-band edit). */
private void patchTableTagsToEmpty(String tableId) throws Exception {
String patchBody = "[{\"op\":\"replace\",\"path\":\"/tags\",\"value\":[]}]";
HttpResponse<String> response =
HTTP_CLIENT.send(
HttpRequest.newBuilder()
.uri(URI.create(SdkClients.getServerUrl() + "/v1/tables/" + tableId))
.header("Authorization", "Bearer " + SdkClients.getAdminToken())
.header("Content-Type", "application/json-patch+json")
.method("PATCH", HttpRequest.BodyPublishers.ofString(patchBody))
.build(),
HttpResponse.BodyHandlers.ofString());
assertEquals(200, response.statusCode(), "PATCH table tags: " + response.body());
}

private Table getTable(String fqn) throws Exception {
HttpRequest request =
HttpRequest.newBuilder()
Expand All @@ -195,7 +293,7 @@ private Table getTable(String fqn) throws Exception {
SdkClients.getServerUrl()
+ "/v1/tables/name/"
+ fqn
+ "?fields=sourceHash&include=all"))
+ "?fields=sourceHash,tags&include=all"))
.header("Authorization", "Bearer " + SdkClients.getAdminToken())
.GET()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,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 537 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
@Getter protected final boolean supportsStyle;
@Getter protected final boolean supportsLifeCycle;
@Getter protected final boolean supportsCertification;
Expand Down Expand Up @@ -4373,6 +4373,11 @@
updated = restorePatchSecrets(original, updated);
}

// A PATCH modifies the entity outside the bulk ingestion path. Clear the sourceHash so the
// next ingestion's bulk fast-path does not skip a re-sync of the source content (e.g. tags
// removed by a UI edit must be re-applied on the next run). The next bulk update re-stamps it.
updated.setSourceHash(null);

updated.setUpdatedBy(user);
updated.setUpdatedAt(System.currentTimeMillis());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ default String getSourceHash() {
return null;
}

default void setSourceHash(String sourceHash) {
// No-op for entities that do not declare sourceHash; overridden by generated classes that do.
}

void setId(UUID id);

void setDescription(String description);
Expand Down
Loading