-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Having trouble querying by KeyProperty #1684
Comments
@nlokare Can we try to throw together a reproducible example? You're inserting the entities from |
@dhermes Exactly. On GCE account_key = datastore.key("Company", account_id)
...
advertiser['client_key'] = account_key
datastore.put(advertiser) On GAE def return_all_advertisers(self, account_id):
all_advertisers = Advertiser.query(Advertiser.client_key == ndb.Key('Company', account_id)).order(Advertiser.advertiser_name).fetch() |
@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. |
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~). |
@pcostell I will try this. However, if my GAE ndb.Key object doesn't contain the 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 |
From GAE I print the key doing: all_advertisers = Advertiser.query().order(Advertiser.advertiser_name).fetch(15)
advert_tester = all_advertisers[0]
test_key = advert_tester.client_key
logging.info(test_key) This is how we discovered that the Entity was saved from GCE with the |
OK I just confirmed: from gcloud import datastore
project = 'MY-PROJ'
client1 = datastore.Client(project=project)
entity1 = datastore.Entity(key=client1.key('Bar', 1))
entity1['foo'] = client1.key('Foo', 1234)
client1.put(entity1)
client2 = datastore.Client(project='s~' + project)
entity2 = datastore.Entity(key=client2.key('Bar', 2))
entity2['foo'] = client2.key('Foo', 1234)
client2.put(entity2) and then from the remote API $ ~/google-cloud-sdk/platform/google_appengine/remote_api_shell.py MY-PROJ
App Engine remote_api shell
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2]
The db, ndb, users, urlfetch, and memcache modules are imported.
s~MY-PROJ> from google.appengine.ext import ndb
s~MY-PROJ> class Foo(ndb.Model):
... pass
...
s~MY-PROJ> class Bar(ndb.Model):
... foo = ndb.KeyProperty(kind='Foo')
...
s~MY-PROJ> q = Bar.query(Bar.foo == ndb.Key(Foo, 1234))
s~MY-PROJ> q.fetch()
[Bar(key=Key('Bar', 2), foo=Key('Foo', 1234))] |
@dhermes So, adding the s~ before the project when initializing |
Yup, that's what @pcostell mentioned above:
|
You could also use |
Sounds good. Closing this for same reason we closed #1639. |
Hi,
I am having trouble querying entities in NDB from AppEngine by
KeyProperty
for entities created with adatastore.Key
from thegcloud.datastore
library. When I log theKeyProperty
of the saved entity on AppEngine, I see a return value ofKey('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 aboveKey
with a query filter such asEntity.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
The text was updated successfully, but these errors were encountered: