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."