Skip to content

Conversation

@stephenplusplus
Copy link
Contributor

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

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.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor Author

After sending this, I found some room for refactoring. But, the process will still be the same, so don't worry about waiting to review

@rakyll
Copy link
Contributor

rakyll commented Sep 19, 2014

LGTM, feel free to merge.

@stephenplusplus
Copy link
Contributor Author

My idea for refactoring quickly made testing more complicated. Will revisit after @ryanseys's API overhaul.

stephenplusplus added a commit that referenced this pull request Sep 19, 2014
datastore: transaction: only commit once
@stephenplusplus stephenplusplus merged commit 245fc17 into googleapis:master Sep 19, 2014
sofisl pushed a commit that referenced this pull request Oct 11, 2022
Fixes #234
Fixes #250

Addressed comments.
sofisl pushed a commit that referenced this pull request Oct 12, 2022
sofisl pushed a commit that referenced this pull request Oct 12, 2022
* fix(docs): reference docs should link to section of googleapis.dev with API reference

* fix(docs): make anchors work in jsdoc
sofisl pushed a commit that referenced this pull request Oct 13, 2022
* changes without context

        autosynth cannot find the source of changes triggered by earlier changes in this
        repository, or by version upgrades to tools such as linters.

* docs: add instructions for authenticating for system tests

* docs: add instructions for authenticating for system tests

* docs: add phrasing change to README

Source-Author: sofisl <55454395+sofisl@users.noreply.github.com>
Source-Date: Mon Dec 21 13:21:29 2020 -0800
Source-Repo: googleapis/synthtool
Source-Sha: 363fe305e9ce34a6cd53951c6ee5f997094b54ee
Source-Link: googleapis/synthtool@363fe30
sofisl pushed a commit that referenced this pull request Oct 13, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this pull request Oct 13, 2022
Fixes #234
Fixes #250

Addressed comments.
sofisl pushed a commit that referenced this pull request Oct 13, 2022
miguelvelezsa pushed a commit that referenced this pull request Jan 28, 2026
Fixes #234
Fixes #250

Addressed comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants