In google app engine, can I call "get_or_insert" from inside a transaction?
The reason I ask is because I'm not sure if there is some conflict with having this run its own transaction inside an already running transaction.
Thanks!
In google app engine, can I call "get_or_insert" from inside a transaction?
The reason I ask is because I'm not sure if there is some conflict with having this run its own transaction inside an already running transaction.
Thanks!
实际上,这取决于您使用的是 NDB 还是旧的 db 包。尼克的回答仅适用于旧的 db 包。但是,在 NDB 中, get_or_insert() 会加入当前事务(如果有的话)。如果在事务外部调用,它会创建自己的事务。这与此处记录的propagation=ALLOWED 的语义相匹配: https ://developers.google.com/appengine/docs/python/ndb/functions#context_options
(尼克在加入现有事务时对实体组的限制是正确的。)
No.get_or_insert
是获取或插入记录的事务函数的语法糖。您可以自己简单地实现它,但这仅在您正在操作的记录与当前事务中的其余实体位于同一实体组中,或者您启用了跨组事务时才有效。