Skip to content

Commit ef2730d

Browse files
Allowing empty merge calls (#144)
1 parent f23c167 commit ef2730d

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

conformance/runner.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ const ignoredRe = [
4343
];
4444

4545
/** If non-empty, list the test cases to run exclusively. */
46-
const exclusiveRe = [];
46+
const exclusiveRe = [
47+
/set: MergeAll cannot be specified with empty data./, // b/73495873
48+
];
4749

4850
const docRef = function(path) {
4951
const relativePath = ResourcePath.fromSlashSeparatedString(path).relativeName;

src/write-batch.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class WriteBatch {
280280

281281
validate.isDocumentReference('documentRef', documentRef);
282282
validate.isDocument('data', data, {
283-
allowEmpty: !merge,
283+
allowEmpty: true,
284284
allowDeletes: merge ? 'all' : 'none',
285285
allowServerTimestamps: true,
286286
});
@@ -292,11 +292,13 @@ class WriteBatch {
292292
const transform = DocumentTransform.fromObject(documentRef, data);
293293
const documentMask = DocumentMask.fromObject(data);
294294

295+
const hasDocumentData = !document.isEmpty || !documentMask.isEmpty;
296+
295297
let write;
296298

297299
if (!merge) {
298300
write = document.toProto();
299-
} else if (!document.isEmpty || !documentMask.isEmpty) {
301+
} else if (hasDocumentData || transform.isEmpty) {
300302
write = document.toProto();
301303
write.updateMask = documentMask.toProto();
302304
}

test/document.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,15 @@ describe('set document', function() {
979979
);
980980
});
981981

982+
it('supports empty merge', function() {
983+
firestore.api.Firestore._commit = function(request, options, callback) {
984+
requestEquals(request, set(document(), updateMask()));
985+
callback(null, writeResult(1));
986+
};
987+
988+
return firestore.doc('collectionId/documentId').set({}, {merge: true});
989+
});
990+
982991
it('supports nested empty merge', function() {
983992
firestore.api.Firestore._commit = function(request, options, callback) {
984993
requestEquals(
@@ -1030,12 +1039,6 @@ describe('set document', function() {
10301039
}, /FieldValue.delete\(\) must appear at the top-level and can only be used in update\(\) or set\(\) with {merge:true}./);
10311040
});
10321041

1033-
it('rejects empty merges', function() {
1034-
assert.throws(() => {
1035-
firestore.doc('collectionId/documentId').set({}, {merge: true});
1036-
}, /At least one field must be updated./);
1037-
});
1038-
10391042
it("doesn't accept arrays", function() {
10401043
assert.throws(() => {
10411044
firestore.doc('collectionId/documentId').set([42]);

0 commit comments

Comments
 (0)