GoogleCloudPlatform/gcloud-node — pull request #234 by stephenplusplus (2014-09-19 17:58:37+00:00)
Title: datastore: transaction: only commit once

I noticed an issue when trying to work with transactions. Here was my code that wasn't working:

```js
var query = /*...*/
dataset.runInTransaction(function(transaction, done) {
transaction.runQuery(query, function(err, entities) {
var keys = entities.map(function(entity) {
return entity.key;
});
transaction.delete(keys, function(err) {
if (err) {/*... */}
done();
});
});
}, function() {/*...*/})
```

This would cause:

```
The referenced transaction has expired or is no longer valid.
```

Behind the scenes, `transaction.delete()` made the `commit` API call with my delete request successfully. However, when I call `done()`, that runs `Transaction.prototype.finalize`, which will try to make another API call to `commit` because nothing marked my transactional operation as `finalized`. `this.isFinalized` is currently only set after a `transaction.rollback()` or `transaction.commit()`. This PR sets `isFinalized = true` from `delete` and `save` as well, if the request is transactional.