Skip to content

Commit 1670ce8

Browse files
TeddyCrCopilot
andauthored
MINOR: regression in export field setter (#27447)
* fix: regression in export field setter * fix: restore hydrateHistoryEntities hook after setFieldsInBulk and update javadoc Agent-Logs-Url: https://github.com/open-metadata/OpenMetadata/sessions/6541c953-9da7-4b9b-9bca-3d3a4792516b Co-authored-by: TeddyCr <13626425+TeddyCr@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TeddyCr <13626425+TeddyCr@users.noreply.github.com>
1 parent 47c88d4 commit 1670ce8

2 files changed

Lines changed: 53 additions & 5 deletions

File tree

openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DatabaseResourceIT.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import static org.junit.jupiter.api.Assertions.assertTrue;
88
import static org.junit.jupiter.api.Assertions.fail;
99

10+
import com.fasterxml.jackson.databind.JsonNode;
11+
import com.fasterxml.jackson.databind.ObjectMapper;
1012
import java.util.HashMap;
1113
import java.util.List;
1214
import java.util.Map;
@@ -35,13 +37,15 @@
3537
import org.openmetadata.schema.type.Column;
3638
import org.openmetadata.schema.type.ColumnDataType;
3739
import org.openmetadata.schema.type.EntityHistory;
40+
import org.openmetadata.schema.type.EntityReference;
3841
import org.openmetadata.schema.type.api.BulkOperationResult;
3942
import org.openmetadata.schema.type.csv.CsvImportResult;
4043
import org.openmetadata.sdk.client.OpenMetadataClient;
4144
import org.openmetadata.sdk.exceptions.InvalidRequestException;
4245
import org.openmetadata.sdk.fluent.Databases;
4346
import org.openmetadata.sdk.models.ListParams;
4447
import org.openmetadata.sdk.models.ListResponse;
48+
import org.openmetadata.sdk.network.HttpMethod;
4549
import org.openmetadata.service.util.FullyQualifiedName;
4650

4751
/**
@@ -1702,4 +1706,47 @@ void testRegexListDatabase_excludeMode(TestNamespace ns) {
17021706
databases.stream().noneMatch(d -> d.getName().startsWith("temp")),
17031707
"Excluded databases should not appear in results");
17041708
}
1709+
1710+
@Test
1711+
void test_listEntityHistoryByTimestamp_returnsServiceField(TestNamespace ns) throws Exception {
1712+
OpenMetadataClient client = SdkClients.adminClient();
1713+
long startTs = System.currentTimeMillis();
1714+
1715+
CreateDatabase createRequest = createRequest(ns.prefix("history_service_field"), ns);
1716+
Database database = createEntity(createRequest);
1717+
1718+
database.setDescription("Updated for history test - " + System.currentTimeMillis());
1719+
patchEntity(database.getId().toString(), database);
1720+
1721+
long endTs = System.currentTimeMillis();
1722+
String basePath = getResourcePath() + "history";
1723+
1724+
String response =
1725+
client
1726+
.getHttpClient()
1727+
.executeForString(
1728+
HttpMethod.GET,
1729+
basePath + "?startTs=" + startTs + "&endTs=" + endTs + "&limit=10",
1730+
null);
1731+
1732+
ObjectMapper mapper = new ObjectMapper();
1733+
JsonNode result = mapper.readTree(response);
1734+
JsonNode data = result.get("data");
1735+
1736+
assertTrue(data.isArray(), "Data should be an array");
1737+
assertTrue(data.size() > 0, "Should have at least one version in the time range");
1738+
1739+
for (JsonNode entityNode : data) {
1740+
assertTrue(
1741+
entityNode.has("service") && !entityNode.get("service").isNull(),
1742+
"Each database version must include the required 'service' field, but got: "
1743+
+ entityNode);
1744+
1745+
Database deserialized = mapper.treeToValue(entityNode, Database.class);
1746+
EntityReference service = deserialized.getService();
1747+
assertNotNull(service, "Deserialized database must have a non-null service reference");
1748+
assertNotNull(service.getId(), "Service reference must have an id");
1749+
assertNotNull(service.getType(), "Service reference must have a type");
1750+
}
1751+
}
17051752
}

openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,7 @@ public final ResultList<T> listEntityHistoryByTimestamp(
22872287
fetchLimit);
22882288

22892289
List<T> entities = JsonUtils.readObjects(jsons, getEntityClass());
2290+
setFieldsInBulk(putFields, entities);
22902291
hydrateHistoryEntities(entities);
22912292

22922293
int total = getVersionCountCached(tableName, startTs, endTs, entityType);
@@ -2325,14 +2326,14 @@ public final ResultList<T> listEntityHistoryByTimestamp(
23252326
}
23262327

23272328
/**
2328-
* Hook to hydrate entities returned from {@link #listEntityHistoryByTimestamp(long, long, String,
2329-
* String, int)}.
2329+
* Hook called after {@link #setFieldsInBulk} for entities returned from {@link
2330+
* #listEntityHistoryByTimestamp(long, long, String, String, int)}.
23302331
*
2331-
* <p>Default behavior is intentionally lightweight: return the historical snapshots as stored in
2332-
* the extension table and avoid expensive relationship re-hydration for each row.
2332+
* <p>Subclasses may override to perform additional, entity-specific hydration of history
2333+
* snapshots without overriding the core field-population logic in {@code setFieldsInBulk}.
23332334
*/
23342335
protected void hydrateHistoryEntities(List<T> entities) {
2335-
// Historical snapshots are already serialized versions; avoid N+1 hydration on /history.
2336+
// No additional hydration by default.
23362337
}
23372338

23382339
private String decodeAndValidateCursor(String cursor) {

0 commit comments

Comments
 (0)