Ryan
Ryan

Reputation: 3

Problem with db.get in Google App Engine

When I run the following code:

    query = datastore.Food_Item.all()
    results = query.fetch(1)
    foodA = results[0]
    foodB = db.get(foodA.key())

I would expect foodA and foodB to be the same type. However, I see that the foodA is of type "model.datastore.Food_Item" and foodB is of type "datastore.Food_Item". Why are they different?

FYI, the Food_Item model is defined in datastore.py, which is found in the "model" directory. I'm new to app engine, so any feedback you could provide would be greatly appreciated. Thanks!

Upvotes: 0

Views: 320

Answers (1)

Nick Johnson
Nick Johnson

Reputation: 101149

It seems likely you're importing the same module (model.datastore) by different names in different places - for example, by using a relative import inside the model package. db.get returns whichever name it saw when the module was first imported, while your own code (the query) returns whatever you explicitly specified.

Upvotes: 4

Related Questions