在Django AppEngine上使用事务 [英] Using transactions on Django AppEngine

查看:145
本文介绍了在Django AppEngine上使用事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AppEngine文档包含一些事务示例,使用AppEngine本机技术对本地对象进行事务处理查询。



通过 http://www.allbuttonspressed.com/projects/django-nonrel [1],我想使用AppEngine事务来查询Django对象。这可能吗?

  def txn():
index = random.randint(0,NUM_SHARDS - 1)
shard_name =shard+ str(index)
counter = SimpleCounterShard.objects.filter(name = shard_name)
#使计数器不存在
如果不是len(counter):
counter = SimpleCounterShard(name = shard_name)
counter.count + = 1
counter.put()
db.run_in_transaction(txn)

目前失败,'只有祖先查询被允许在一个事务中。'我理解这是要求我做一些涉及祖先类的事情,但是我我不确定是什么或为什么。



任何提示?

[1]你不能使用Django的交易API。支持一种特殊的事务(例如,App Engine上的run_in_transaction()),您必须使用平台特定的功能。

然而,在这个djangoappengine的开发者分支中有非官方的支持。 10rel =nofollow> https://github.com/django-nonrel/djangoappengine/pull/10



补丁尚未完成,但我计划在接下来的几周内尝试它,并会在这里更新。


The AppEngine documentation has a few examples of transactions, using the AppEngine native technique to make transacted queries on native objects.

Per the docs at http://www.allbuttonspressed.com/projects/django-nonrel [1], I'd like to use AppEngine transactions to query Django objects. Is this possible?

def txn():
    index = random.randint(0, NUM_SHARDS - 1)
    shard_name = "shard" + str(index)
    counter = SimpleCounterShard.objects.filter(name=shard_name)
    # Make counter if it doesn't exist 
    if not len(counter):
        counter = SimpleCounterShard(name=shard_name)
    counter.count += 1
    counter.put()
db.run_in_transaction(txn)

This currently fails with 'Only ancestor queries are allowed inside a transaction.' I understand this is asking me to do something involving an ancestor class, but I'm not sure what or why.

Any tips?

[1] "You can't use Django's transactions API. If your particular DB supports a special kind of transaction (e.g., run_in_transaction() on App Engine) you have to use the platform-specific functions."

解决方案

Nailer hit it on the head in his answer (sorry for the pun): DjangoAE does not support entity groups. However, there is unofficial support in this enterprising developer's branch of djangoappengine.

https://github.com/django-nonrel/djangoappengine/pull/10

The patch is not yet complete, but I plan on trying it out in the next few weeks and will update here.

这篇关于在Django AppEngine上使用事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆