Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Descendants entities losing database ID from parent (#3142) #3156

Merged
merged 2 commits into from
Sep 4, 2024
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 @@ -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());
Copy link
Member

Choose a reason for hiding this comment

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

It's too bad the ancestors can't be explicitly cleared in the builder, or we'd be able to use the copy constructors to avoid direct knowledge of all the individual fields.

public static Key getKeyWithoutAncestors(Key entityKey) {
  return Key.newBuilder(entityKey).withoutAncestors().build();
}


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);
}
}
Loading