Reputation: 119
first time post and new to google app engine!
i can't for the life of me figure out why my attempts to access an object using Model.get_by_id does not function.
my test data is populated and i can verify the output as commented. i can confirm the ID of the data in the Datastore viewer... but attempts to use that ID fail to return the object.
namespace_manager.set_namespace('myNamespace') for t in models.MyClass.all().fetch(100): print t.key().id() # prints the key and verified in the Datastore Viewer print t.date # prints the date myClassInstance = models.MyClass.get_by_id(t.key().id()) # never finds the object if tour is None: print "MyClass instance not found"
so output is
6 2012-04-24 20:47:13.537000 MyClass instance not found 27 2012-04-24 20:47:13.605000 MyClass instance not found 29 2012-04-24 20:47:13.611000 MyClass instance not found 31 2012-04-24 20:47:13.617000 MyClass instance not found
note that this is not a root entity and has children as well... but shouldn't the MyClass.get_by_id method return the correct object?
thanks in advance!
Upvotes: 0
Views: 466
Reputation: 7158
if you are creating your entities with a parent/ancestor you need to provide that to the get_by_id
function too.
entity = MyModel(parent = parentkey,
name = 'somename')
entity.put()
entity_by_id = MyModel.get_by_id(entity.key().id(), parent = parentkey)
Upvotes: 3