From bddcda33a9ca4eaa31254272fb0f382a9c1806c6 Mon Sep 17 00:00:00 2001 From: Silvano Luciani Date: Tue, 22 Jul 2014 17:52:54 -0700 Subject: [PATCH 1/2] Fixes for runInTransaction * always pass a value for json in makeReq so that request takes care of sending headers for json and parsing object from response body * read the correct value for transaction id * couple of typos and other minor fixes --- lib/datastore/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/datastore/index.js b/lib/datastore/index.js index 53ebc0acb1c..1c42355a239 100644 --- a/lib/datastore/index.js +++ b/lib/datastore/index.js @@ -46,7 +46,7 @@ Transaction.prototype.begin = function(callback) { var that = this; this.makeReq('beginTransaction', null, function(err, resp) { if (!err) { - that.id = resp; + that.id = resp.transaction; } callback && callback(err); }); @@ -69,7 +69,7 @@ Transaction.prototype.rollback = function(callback) { /** * Commit commits the remote transaction and finalizes the - * current transaction insance. + * current transaction instance. */ Transaction.prototype.commit = function(callback) { var that = this; @@ -77,13 +77,14 @@ Transaction.prototype.commit = function(callback) { this.makeReq('commit', req, function(err, resp) { if (!err) { that.isFinalized = true; + that.id = null; } callback && callback(err); }); }; /** - * Finalize commits a transction if it's not finalized yet. + * Finalize commits a transaction if it's not finalized yet. */ Transaction.prototype.finalize = function(callback) { if (!this.isFinalized) { @@ -182,7 +183,7 @@ Transaction.prototype.saveAll = function(keys, objs, callback) { } for (var i = 0; i < keys.length; i++) { var e = entity.entityToEntityProto(objs[i]); - e.key = entity.keyToKeyProto(this.id, keys[i]); + e.key = entity.keyToKeyProto(this.datasetId, keys[i]); if (entity.isKeyComplete(keys[i])) { req.mutation.upsert.push(e); } else { @@ -294,6 +295,8 @@ Transaction.prototype.mapQuery = function(q, mapperFn, opt_callback) { */ Transaction.prototype.makeReq = function(method, req, callback) { // TODO(jbd): Switch to protobuf API. + // Always pass a value for json to automagically get headers/response parsing. + req = req || {}; this.conn.req({ method: 'POST', uri: DATASTORE_BASE_URL + '/' + this.datasetId + '/' + method, From b94039c21fe15ffee12157579641a1c41da72b7d Mon Sep 17 00:00:00 2001 From: Silvano Luciani Date: Tue, 22 Jul 2014 21:09:23 -0700 Subject: [PATCH 2/2] Made more clear that json should be true and removed wrongly committed line. --- lib/datastore/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/datastore/index.js b/lib/datastore/index.js index 1c42355a239..5122faf73f2 100644 --- a/lib/datastore/index.js +++ b/lib/datastore/index.js @@ -77,7 +77,6 @@ Transaction.prototype.commit = function(callback) { this.makeReq('commit', req, function(err, resp) { if (!err) { that.isFinalized = true; - that.id = null; } callback && callback(err); }); @@ -296,7 +295,7 @@ Transaction.prototype.mapQuery = function(q, mapperFn, opt_callback) { Transaction.prototype.makeReq = function(method, req, callback) { // TODO(jbd): Switch to protobuf API. // Always pass a value for json to automagically get headers/response parsing. - req = req || {}; + req = req || true; this.conn.req({ method: 'POST', uri: DATASTORE_BASE_URL + '/' + this.datasetId + '/' + method,