我在 GAP 中使用 python 并尝试使用db.delete(model_obj)
. delete()
我想这个操作是同步进行的,因为文档告诉了和之间的区别delete_async()
,但是当我阅读数据库中的源代码时,删除方法只是简单地调用了delete_async
,这与文档所说的不匹配:(
那么有没有人可以在同步流中删除?这是db中的源代码:
def delete_async(models, **kwargs):
"""Asynchronous version of delete one or more Model instances.
Identical to db.delete() except returns an asynchronous object. Call
get_result() on the return value to block on the call.
"""
if isinstance(models, (basestring, Model, Key)):
models = [models]
else:
try:
models = iter(models)
except TypeError:
models = [models]
keys = [_coerce_to_key(v) for v in models]
return datastore.DeleteAsync(keys, **kwargs)
def delete(models, **kwargs):
"""Delete one or more Model instances.
"""
delete_async(models, **kwargs).get_result()
编辑:从评论中,这是原始的行为不端代码:
def tearDown(self):
print self.account
db.delete(self.device)
db.delete(self.account)
print Account.get_by_email(self.email, case_sensitive=False)
两个打印语句的结果是<Account object at 0x10d1827d0>
<Account object at 0x10d1825d0>
。即使两个内存地址不同,但它们指向同一个对象。如果我在删除之类的 for 循环之后放置一些延迟,则获取的对象为无。