Skip to content

runQuery doesn't run inside transaction #905

Description

@pcostell

Sorry if this isn't right, I only noticed it through inspection.

It looks like Transaction extends from DatastoreRequest, which means it gets a runQuery method. However, it doesn't look like it overrides it. This means a user who thinks they are running a query in the transaction is actually going to get inconsistent results.

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    api: datastoreIssues related to the Datastore API.
    on Oct 5, 2015
  2. stephenplusplus commented on Oct 6, 2015

    @stephenplusplus
    Contributor

    I think it will work as intended. When the API request is made, it goes through this method: https://github.com/GoogleCloudPlatform/gcloud-node/blob/69046d383af6bf67a316739c66650601228abc8a/lib/datastore/request.js#L759:

    DatastoreRequest.prototype.makeReq_ = function(method, body, callback) {
      // ...
    
      if (method === 'lookup' && this.id) {
        body.read_options = body.read_options || {};
        body.read_options.transaction = this.id;
      }
    
      // ...

    this.id is set to the transaction ID when using a Transaction object.

  3. pcostell commented on Oct 6, 2015

    @pcostell
    ContributorAuthor

    That's if the method is 'lookup'. But what if the method is 'runQuery'?

  4. stephenplusplus commented on Oct 6, 2015

    @stephenplusplus
    Contributor

    Ah, woops. So I think we just need this.id && (method === 'lookup' || method === 'runQuery').

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

Metadata

Metadata

Labels

api: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions