willem
willem

Reputation: 27027

On the google app engine, why do updates not reflect in a transaction?

I store groups of entities in the google app engine Data Store with the same ancestor/parent/entityGroup. This is so that the entities can be updated in one atomic datastore transaction.

The problem is as follows:

  1. I start a db transaction
  2. I update entityX by setting entityX.flag = True
  3. I save entityX
  4. I query for entity where flag == True. BUT, here is the problem. This query does NOT return any results. It should have returned entityX, but it did not.

When I remove the transaction, my code works perfectly, so it must be the transaction that is causing this strange behavior.

Should updates to entities in the entity group not be visible elsewhere in the same transaction?

PS: I am using Python. And GAE tells me I can't use nested transactions :(

Upvotes: 2

Views: 229

Answers (2)

Saxon Druce
Saxon Druce

Reputation: 17624

App Engine's transactions are designed that way, ie reads within a transaction see a snapshot as of the beginning of the transaction, so they don't see the result of earlier writes within the transaction:

http://code.google.com/appengine/docs/python/datastore/transactions.html#Isolation_and_Consistency

Upvotes: 4

naikus
naikus

Reputation: 24472

Looks like you are not doing a commit on the transaction before querying

  1. start a db transaction
  2. update entityX by setting entityX.flag = True
  3. save entityX
  4. COMMIT TRANSACTION
  5. query for entity where flag == True. BUT, here is the problem. This query does NOT return any results. It should have returned entityX, but it did not.

In a transaction, entities will not be persisted until the transaction is commited

Upvotes: 0

Related Questions