diff --git a/lib/datastore/request.js b/lib/datastore/request.js index 3f7e3277494..e47e3ff9396 100644 --- a/lib/datastore/request.js +++ b/lib/datastore/request.js @@ -253,12 +253,15 @@ DatastoreRequest.prototype.save = function(entities, callback) { callback(err); return; } + if (this.id) { + this.isFinalized = true; + } var autoInserted = (resp.mutation_result.insert_auto_id_key || []); autoInserted.forEach(function(key, index) { keys[insertIndexes[index]] = entity.keyFromKeyProto(key); }); callback(null, isMultipleRequest ? keys : keys[0]); - }); + }.bind(this)); }; /** @@ -300,7 +303,12 @@ DatastoreRequest.prototype.delete = function(keys, callback) { } req = new pb.CommitRequest(req); var res = pb.CommitResponse; - this.createRequest_('commit', req, res, callback); + this.createRequest_('commit', req, res, function(err) { + if (!err && this.id) { + this.isFinalized = true; + } + callback.apply(null, util.toArray(arguments)); + }.bind(this)); }; /**