get_by_id in google app engine python ndb responds with None
app-engine-ndb, google-app-engine
Solution
This problem occur when you have the key as string, the simplest solution is:
Model.get_by_id(int(id))
This problem is most likely to appear is when you read the id from url and the like:
class MyHandler(webapp2.RequestHandler):
def get(self, id):
instance = Model.get_by_id(int(id))
Problem
I'm having trouble using `get_by_id` in google app engine python ndb. Python Code Attempt 1 ``` resource = Content.get_by_id(6093630880088064) ``` resource is `None` Attempt 2 ``` resource = Content.get_by_id(6093630880088064, parent = 5249205949956096) ``` `BadValueError: Expected Key instance, got 5249205949956096L` Attempt 3 ``` key_parent = ndb.Key('Subject', '5249205949956096') resource = Content.get_by_id(6093630880088064, parent = key_parent) ``` resource is `None` Datastore ``` Entity Kind Content Entity Key ahBkZXZ-YnJhaW5ib290ZWNocigLEgdTdWJqZWN0GICAgICAxKkJDAsSB0NvbnRlbnQYgICAgIDE6QoM ID 6093630880088064 Parent ahBkZXZ-YnJhaW5ib290ZWNochQLEgdTdWJqZWN0GICAgICAxKkJDA Subject:id=5249205949956096 ``` Any suggestions would be greatly appreciated. My goal is that resource will be an object where I can do something like `resource.name` to retrieve the name property.