diff --git a/lib/datastore/request.js b/lib/datastore/request.js index 8fa08e02084..5c770659fae 100644 --- a/lib/datastore/request.js +++ b/lib/datastore/request.js @@ -760,7 +760,7 @@ DatastoreRequest.prototype.makeReq_ = function(method, body, callback) { body.transaction = this.id; } - if (method === 'lookup' && this.id) { + if (this.id && (method === 'lookup' || method === 'runQuery')) { body.read_options = body.read_options || {}; body.read_options.transaction = this.id; } diff --git a/test/datastore/request.js b/test/datastore/request.js index 1adf425f40c..85c09eac445 100644 --- a/test/datastore/request.js +++ b/test/datastore/request.js @@ -1107,6 +1107,31 @@ describe('Request', function() { request.makeReq_('lookup', util.noop); }); }); + + describe('runQuery', function() { + it('should attach transactional properties', function(done) { + request.id = 'EeMXCSGvwcSWGkkABRmGMTWdbi_pa66VflNhQAGblQFMXf9HrmNGa' + + 'GugEsO1M2_2x7wZvLencG51uwaDOTZCjTkkRh7bw_oyKUgTmtJ0iWJwath7'; + var expected = new pb.RunQueryRequest({ + read_options: { + transaction: request.id + } + }).toBuffer(); + requestOverride = function(req) { + assert.deepEqual(req.body, expected); + done(); + }; + request.makeReq_('runQuery', util.noop); + }); + + it('should not attach transactional properties', function(done) { + requestOverride = function(req) { + assert.strictEqual(req.body, ''); + done(); + }; + request.makeReq_('runQuery', util.noop); + }); + }); }); }); });