-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
There was a problem hiding this 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.
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…#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.
* 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.
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