You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having trouble querying entities in NDB from AppEngine by KeyProperty for entities created with a datastore.Key from the gcloud.datastore library. When I log the KeyProperty of the saved entity on AppEngine, I see a return value of Key('Company', '273', app='random_project_id'). Because I am attempting to query by Key Literal on AppEngine, it looks like NDB does not recognize the above Key with a query filter such as Entity.query(Entity.key_property == ndb.Key('Company', '273').fetch(). This query should return an iterator with various entities.
Is this a potential bug with gcloud or with AppEngine? @lexsf@vliang63
@nlokare Can we try to throw together a reproducible example? You're inserting the entities from gcloud-python and then the GAE / ndb queries are failing, yes?
@dhermes Just to clarify, my queries work on GAE when developing locally because we seed our datastore directly from GAE. Alternatively, in production/staging we are populating our datastore from GCE. Our GAE application is essentially only reading from the datastore.
@pcostell I will try this. However, if my GAE ndb.Key object doesn't contain the project_id keyword argument, I think that this will still fail, since the creation of the entity from GCE added the extra data to the Key that wasn't implicit in the GAE query. Does that make sense?
In the pseudo-code above, I initialized the datastore object with our project. I left that out in the code snippet.
How do you print the key? Can you try printing key.app() directly? ndb.Key's default __repr__won't print the application ID if it matches the current app.
Activity
dhermes commentedon Mar 30, 2016
@pcostell WDYT? Seems it may be related to #1639
dhermes commentedon Mar 31, 2016
@nlokare Can we try to throw together a reproducible example? You're inserting the entities from
gcloud-pythonand then the GAE /ndbqueries are failing, yes?nlokare commentedon Mar 31, 2016
@dhermes Exactly.
On GCE
On GAE
nlokare commentedon Mar 31, 2016
@dhermes Just to clarify, my queries work on GAE when developing locally because we seed our datastore directly from GAE. Alternatively, in production/staging we are populating our datastore from GCE. Our GAE application is essentially only reading from the datastore.
pcostell commentedon Mar 31, 2016
Sounds like the same issue as #1639. Same as that issue, I think this will be fixed in v1beta3 if we always populate the project in 'gcloud-python'.
@nlokare Can you try again but with something like this on GCE:
Where the application contains your project ID but with the extra information (likely s~).
nlokare commentedon Mar 31, 2016
@pcostell I will try this. However, if my GAE ndb.Key object doesn't contain the
project_idkeyword argument, I think that this will still fail, since the creation of the entity from GCE added the extra data to the Key that wasn't implicit in the GAE query. Does that make sense?In the pseudo-code above, I initialized the datastore object with our project. I left that out in the code snippet.
pcostell commentedon Mar 31, 2016
How do you print the key? Can you try printing
key.app()directly?ndb.Key's default__repr__won't print the application ID if it matches the current app.nlokare commentedon Mar 31, 2016
From GAE I print the key doing:
This is how we discovered that the Entity was saved from GCE with the
client_keyproperty asKey('Company', '273', app='random_project_id')dhermes commentedon Mar 31, 2016
OK I just confirmed:
and then from the remote API
nlokare commentedon Mar 31, 2016
@dhermes So, adding the s~ before the project when initializing
datastore.Clientwill solve this?dhermes commentedon Mar 31, 2016
Yup, that's what @pcostell mentioned above:
nlokare commentedon Mar 31, 2016
@dhermes @pcostell Ok, great. I will try this and report back. Thanks for help!
dhermes commentedon Mar 31, 2016
You could also use
find_true_projectbut that all is moot inv1beta3.nlokare commentedon Mar 31, 2016
@dhermes @pcostell Reporting back. Looks like this was the fix we needed. Thank you gentlemen.
dhermes commentedon Mar 31, 2016
Sounds good. Closing this for same reason we closed #1639.
test: fix issue in tests related to json serialization (#1684)
chore(deps): bump urllib3 from 1.26.15 to 1.26.18 in /samples/geograp…
fix: Guarantee guid thread safety across threads (#1684)
docs: migrate code from googleapis/python-bigquery (#18303)