Transactions

There are cases where you'd want a number of operations to succeed or fail altogether and nothing in between. This is called a transaction, and App Engine's datastore offers support for transactions. In App Engine, you do this by encapsulating all the steps that you want to fail or succeed together in a function and decorate it with the ndb.transactional decorator.

Let's suppose that it so happens that we add a new property called city to indicate the city that the car is in. Sometimes, two cars are exchanged between two dealers in two difference cities. In that case, we need to update the cities of these two listings and basically swap them. There are multiple datastore operations involved here, given that we have keys for both the ...

Get Mastering Google App Engine now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.