Skip to content

fix(datastore): Correcting string representation of Key #8363

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

Merged
merged 3 commits into from
Aug 8, 2023

Conversation

bhshkh
Copy link
Contributor

@bhshkh bhshkh commented Jul 31, 2023

Issue: While getting entities from Datastore, if the queried keys have same Kind and name/ID but different namespaces, then only one of the entities get retrieved

Cause: When entities are returned from Datastore in LookupResponse, they are not in the order in which the Keys are sent. E.g. If keys sent were:{ {kind, name1, namespace1}, {kind, name2, namespace1 }, {kind, name3, namespace1 }}, The response can be {entity3, entity1, entity2} instead of {entity1, entity2, entity3}.
To make it easier for users to consume, the library arranges the entities in the order of keys before returning them to user.

To do this, all the keys are reverse mapped to their index in the input array and then the entities received from Datastore are put at the index of the input keys in the response array. For above example, the map created is {"kind,name1": 0, "kind, name2": 1, "kind,name3": 2}. As can be seen here, the keys in the map do not take into account the namespace. So, if 2 keys have different namespaces the entities response gets overwritten.

Fix: Add namespace to key in the reverse map

@bhshkh bhshkh requested review from a team as code owners July 31, 2023 20:32
@bhshkh bhshkh enabled auto-merge (squash) July 31, 2023 20:32
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: datastore Issues related to the Datastore API. labels Jul 31, 2023
@bhshkh bhshkh assigned bhshkh and unassigned bhshkh Jul 31, 2023
@bhshkh bhshkh linked an issue Jul 31, 2023 that may be closed by this pull request
@bhshkh bhshkh requested a review from enocom July 31, 2023 20:51
Copy link
Member

@enocom enocom left a comment

Choose a reason for hiding this comment

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

Could we add a description to each test case to explain what it's testing. As written, this test requires careful study to understand what it's doing.

@bhshkh bhshkh requested a review from enocom August 7, 2023 18:58
@bhshkh
Copy link
Contributor Author

bhshkh commented Aug 7, 2023

Could we add a description to each test case to explain what it's testing. As written, this test requires careful study to understand what it's doing.

Done

Copy link
Member

@enocom enocom left a comment

Choose a reason for hiding this comment

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

LGTM

@bhshkh bhshkh merged commit 4cb1211 into googleapis:main Aug 8, 2023
@bhshkh bhshkh deleted the fix/issue-7829 branch August 22, 2023 19:57
sgp added a commit to sgp/google-cloud-go that referenced this pull request Sep 5, 2024
…#10684)

fix(datastore): remove namespace from Key.String()

Fixes googleapis#10684.

Datastore namespaces may be sensitive, and it's best not to emit them.

Restores the behavior of `Key.String` prior to googleapis#8363, but maintains the
fix for googleapis#7829 by providing an internal implementation that does provide
the namespace.
bhshkh pushed a commit that referenced this pull request Sep 5, 2024
* fix(datastore): remove namespace from Key.String() (#10684)

Datastore namespaces may be sensitive, and it's best not to emit
them.

Provide a `datastore.Key.StringWithNamespace()` as an alternative,
and use this version internally, which preserves the fix from
#7829.

* amend! fix(datastore): remove namespace from Key.String() (#10684)

fix(datastore): remove namespace from Key.String()

Fixes #10684.

Datastore namespaces may be sensitive, and it's best not to emit them.

Restores the behavior of `Key.String` prior to #8363, but maintains the
fix for #7829 by providing an internal implementation that does provide
the namespace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

datastore: equal keys in different namespaces are deduped incorrectly
3 participants