To answer your question in one word: yes, your second example is a way to do this. Within the boundaries of the transaction, you get some data, change it and fix the new value.
Your first is not wrong because you are not reading obj . Therefore, even if it may not have the same meaning as before, you will not notice. In other words: as written, your examples do not very well illustrate the point of the transaction, which is usually called the "test and set." See a Good Wikipedia article: http://en.wikipedia.org/wiki/Test-and-set
More specifically for GAE, as defined in GAE docs , transaction:
A set of Datastore operations for one or more objects. Each transaction is guaranteed to be atomic, which means that transactions are never partially applied. Either all operations in the transaction are used, or none of them are used.
which tells you that it should not be easy for testing and installation, it can also be useful for providing batch commit of several objects, etc.
source share