Skip to content

Commit

Permalink
fix: Descendants entities losing database ID from parent (#3142) (#3156)
Browse files Browse the repository at this point in the history
* fix: need to also send database ID when migrating keys from ancestor to child
  • Loading branch information
ldetmer authored Sep 4, 2024
1 parent 96890b8 commit 02a1e65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static Key getKeyWithoutAncestors(Key entityKey) {
Key.newBuilder(entityKey.getProjectId(), entityKey.getKind(), entityKey.getId());
}
ancestorLookupKey.setNamespace(entityKey.getNamespace());
ancestorLookupKey.setDatabaseId(entityKey.getDatabaseId());

return ancestorLookupKey.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,29 @@ void testRemoveAncestors_IdKeys() {
Key processedKey = KeyUtil.getKeyWithoutAncestors(idKey);
assertThat(processedKey.getAncestors()).isEmpty();
}

@Test
void testAncestorKeys_containsAllDataStoreMetaData() {
String projectId = "project-id";
String kind = "kind";
Long id = 13L;
String databaseId = "database-id";
String namespace = "namespace";

Key idKey =
Key.newBuilder(projectId, kind, id, databaseId)
.setNamespace(namespace)
.addAncestor(PathElement.of("person", 22L))
.addAncestor(PathElement.of("person", 18L))
.build();

Key processedKey = KeyUtil.getKeyWithoutAncestors(idKey);

assertThat(processedKey.getAncestors()).isEmpty();
assertThat(processedKey.getId()).isEqualTo(id);
assertThat(processedKey.getKind()).isEqualTo(kind);
assertThat(processedKey.getDatabaseId()).isEqualTo(databaseId);
assertThat(processedKey.getNamespace()).isEqualTo(namespace);
assertThat(processedKey.getProjectId()).isEqualTo(projectId);
}
}

0 comments on commit 02a1e65

Please sign in to comment.