1

我目前正在使用 django non-rel web 框架开发一个谷歌应用引擎应用程序。我有一种方法可以将钱从一个帐户转移到另一个帐户,非常简单。当我使用调试器在本地服务器上运行它时,它工作得很好并且可以正确转移所有资金。但是,当我在应用程序引擎上远程运行它时,我会得到奇怪的负值。该方法的关键在于:

pubAccount.secondary_money = pubAccount.secondary_money + transaction.money
pubAccount.money = pubAccount.money - transaction.money

经过广泛的研究,我发现这可能是由于我没有使用交易,这意味着传输绝不是原子的,因此可能会发生竞争条件。但是 django non-rel 不能正确支持事务,并且它支持的部分不直接被应用程序引擎支持,并且据我发现,python-app 引擎工具包支持的任何东西都不受 django non-rel 支持.

所以谁能告诉我如何使用 django non-rel 在应用程序引擎上进行交易!?一定有人把它搞定了!

4

1 回答 1

1

简单,使用db.run_in_transaction()

编辑:

如果有帮助,这是我使用的分支,运行 django-1.4,支持祖先查询。

https://github.com/dragonx/djangoappengine.git -> django-1.4 branch
https://github.com/dragonx/django-1.4.git -> 1.4-nonrel branch
https://github.com/dragonx/djangotoolbox.git -> features/django-1.4 branch
https://github.com/dragonx/django-dbindexer.git -> develop branch (although the 1.4wip branch looks better)
于 2012-11-16T19:46:10.647 回答