开发者

Google App Engine : alternate method of get_by_id()

开发者 https://www.devze.com 2023-03-04 15:14 出处:网络
By given an entity ID , I will query b开发者_JS百科y models = Model.get_by_id(id). However, I find out that some time it will not return result collectly.

By given an entity ID , I will query b开发者_JS百科y models = Model.get_by_id(id). However, I find out that some time it will not return result collectly.

Is there any alternative or recommended method to query by entity ID in Google App Engine, python?


If you are saving your class instances with a parent then get_by_id will not return the object but instead will return None due to the reason that the key is not complete thus requiring the parent key as well. I encountered the same issue and was a pain in the ass to figure out.

ico = Icons.get_by_id("3", parent = parentkey)

This will return an object. ;-)


If Model.get_by_id(id) returns None, this indicates that you've supplied an invalid ID, not that the method itself is unreliable.

It's not inconceivable that this method could fail in the event of a system outage, but if it did, your call would throw a datastore exception, not return an empty result.


The problem disappear by itself after the 2011-05-10, which is the v1.5 launch date. Not sure this problem is related.

I didn't change any code, as the get_by_id() was fine all the while and on this few days. Beside, I added a cron job to run the get_by_id() every minutes and try to get the instance alive.

From my observation, the get_by_id() failed because it couldn't query the datastore.

Btw, the setting of datastore is Master/Slave Replication.


get_by_id() always get the object, if the passed object is a valid id of object and if the objects exists in the datastore.

id can be got by object.key.id in the templat

else you always have the object.get(key).

0

精彩评论

暂无评论...
验证码 换一张
取 消