Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/datastore/src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ var flatten = require('lodash.flatten');
var prop = require('propprop');
var util = require('util');

/**
* @type {module:datastore/entity}
* @private
*/
var entity = require('./entity.js');

/**
* @type {module:datastore/request}
* @private
Expand Down Expand Up @@ -129,10 +135,16 @@ Transaction.prototype.commit = function(callback) {
// key they just asked to be deleted, the delete request will be ignored,
// giving preference to the save operation.
.filter(function(modifiedEntity) {
var key = JSON.stringify(modifiedEntity.entity.key);
var key = modifiedEntity.entity.key;

if (!entity.isKeyComplete(key)) {
return true;
}

var stringifiedKey = JSON.stringify(modifiedEntity.entity.key);

if (!keys[key]) {
keys[key] = true;
if (!keys[stringifiedKey]) {
keys[stringifiedKey] = true;
return true;
}
})
Expand Down
14 changes: 14 additions & 0 deletions packages/datastore/test/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,20 @@ describe('Transaction', function() {
assert.equal(saveCalled, 1);
});

it('should not squash key-incomplete mutations', function(done) {
transaction.save({ key: key(['Product']), data: '' });
transaction.save({ key: key(['Product']), data: '' });

DatastoreRequestOverride.save = function(entities) {
assert.strictEqual(entities.length, 2);
done();
};

transaction.request_ = util.noop;

transaction.commit();
});

it('should send the built request object', function(done) {
transaction.requests_ = [
{
Expand Down