File tree 2 files changed +29
-3
lines changed
2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,12 @@ var flatten = require('lodash.flatten');
26
26
var prop = require ( 'propprop' ) ;
27
27
var util = require ( 'util' ) ;
28
28
29
+ /**
30
+ * @type {module:datastore/entity }
31
+ * @private
32
+ */
33
+ var entity = require ( './entity.js' ) ;
34
+
29
35
/**
30
36
* @type {module:datastore/request }
31
37
* @private
@@ -129,10 +135,16 @@ Transaction.prototype.commit = function(callback) {
129
135
// key they just asked to be deleted, the delete request will be ignored,
130
136
// giving preference to the save operation.
131
137
. filter ( function ( modifiedEntity ) {
132
- var key = JSON . stringify ( modifiedEntity . entity . key ) ;
138
+ var key = modifiedEntity . entity . key ;
139
+
140
+ if ( ! entity . isKeyComplete ( key ) ) {
141
+ return true ;
142
+ }
143
+
144
+ var stringifiedKey = JSON . stringify ( modifiedEntity . entity . key ) ;
133
145
134
- if ( ! keys [ key ] ) {
135
- keys [ key ] = true ;
146
+ if ( ! keys [ stringifiedKey ] ) {
147
+ keys [ stringifiedKey ] = true ;
136
148
return true ;
137
149
}
138
150
} )
Original file line number Diff line number Diff line change @@ -261,6 +261,20 @@ describe('Transaction', function() {
261
261
assert . equal ( saveCalled , 1 ) ;
262
262
} ) ;
263
263
264
+ it ( 'should not squash key-incomplete mutations' , function ( done ) {
265
+ transaction . save ( { key : key ( [ 'Product' ] ) , data : '' } ) ;
266
+ transaction . save ( { key : key ( [ 'Product' ] ) , data : '' } ) ;
267
+
268
+ DatastoreRequestOverride . save = function ( entities ) {
269
+ assert . strictEqual ( entities . length , 2 ) ;
270
+ done ( ) ;
271
+ } ;
272
+
273
+ transaction . request_ = util . noop ;
274
+
275
+ transaction . commit ( ) ;
276
+ } ) ;
277
+
264
278
it ( 'should send the built request object' , function ( done ) {
265
279
transaction . requests_ = [
266
280
{
You can’t perform that action at this time.
0 commit comments