Timm
Timm

Reputation: 12753

get_by_id doesn't seem to get by id

There is an entity in the Questions table with ID 6544293208522752. When I try to get this back using Questions.get_by_id(6544293208522752) it returns None.

------ Update

To get the parent, categoryKey is just being passed in as an integer:

def questionsKey(categoryKey):
    return ndb.Key('Questions', categoryKey)

QuestionID is obtained via a get request, one page sends question.key.id(), the other gets it with questionID = int(self.request.get('ID'))

Upvotes: 0

Views: 89

Answers (2)

aschmid00
aschmid00

Reputation: 7158

because you are storing the entity with a parent you need to provide that to the get_by_id function too.

entity = Questions.get_by_id(6544293208522752, parent=questionsKey(questionCategory))

otherwise you wont get the entity back.

Upvotes: 1

Greg
Greg

Reputation: 10360

Are you mixing up string and int IDs? Datastore models can have either, but they're not the same. (The auto-generated IDs are ints but, for example, an ID passed as a URL parameter will be a string and you'll need to convert it.)

Upvotes: 1

Related Questions