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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access