Skip to content

Commit f695cc3

Browse files
---
yaml --- r: 9043 b: refs/heads/mrschmidt-emptymerge c: 447dbdd h: refs/heads/master i: 9041: 891c1a9 9039: 0f829c7
1 parent c91d7f2 commit f695cc3

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ refs/tags/v0.30.0: 9ea3a32084835d0499934e7c070af9f120747e88
8989
refs/heads/batching-expr: 95bc1ac20addaeb25ef65f62450593ed600484b9
9090
"refs/heads/datastore_orderby_tostring": 24a5a107969714ebb69a5a098f47658f7b1e8689
9191
"refs/heads/mrschmidt-__name___": effe27458f7d31b1d5ae1af6a5a228ce89c33462
92-
refs/heads/mrschmidt-emptymerge: 1fc5c1bbba7c0713ed9c2b31c6c673621f48b981
92+
refs/heads/mrschmidt-emptymerge: 447dbddebbcb8b88fe5dc480d16c0c7697712d11

branches/mrschmidt-emptymerge/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ private T performSet(
245245
DocumentTransform.fromFieldPathMap(documentReference, documentData);
246246

247247
if (options.isMerge()) {
248-
Preconditions.checkArgument(!fields.isEmpty(), "Data to merge cannot be empty.");
249248
if (options.getFieldMask() != null) {
250249
List<FieldPath> fieldMask = new ArrayList<>(options.getFieldMask());
251250
fieldMask.removeAll(documentTransform.getFields());
@@ -257,11 +256,12 @@ private T performSet(
257256

258257
Mutation mutation = addMutation();
259258

260-
if (!options.isMerge() || !documentSnapshot.isEmpty() || !documentMask.isEmpty()) {
261-
mutation.document = documentSnapshot.toPb();
262-
}
259+
boolean hasDocumentData = !documentSnapshot.isEmpty() || !documentMask.isEmpty();
263260

264-
if (!documentMask.isEmpty()) {
261+
if (!options.isMerge()) {
262+
mutation.document = documentSnapshot.toPb();
263+
} else if (hasDocumentData || documentTransform.isEmpty()) {
264+
mutation.document = documentSnapshot.toPb();
265265
mutation.document.setUpdateMask(documentMask.toPb());
266266
}
267267

branches/mrschmidt-emptymerge/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public class ConformanceTest {
8585
private interface ConformanceTestCase extends Test, Describable {}
8686

8787
/** Excluded tests by test description. */
88-
private final Set<String> excludedTests = Collections.emptySet();
88+
private final Set<String> excludedTests =
89+
Collections.singleton("set: MergeAll cannot be specified with empty data."); // b/73495873
8990

9091
/** If non-empty, only runs tests included in this set. */
9192
private final Set<String> includedTests = Collections.emptySet();

branches/mrschmidt-emptymerge/google-cloud-firestore/src/test/java/com/google/cloud/firestore/DocumentReferenceTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,20 @@ public void setDocumentWithMerge() throws Exception {
411411
}
412412
}
413413

414+
@Test
415+
public void setDocumentWithEmptyMerge() throws Exception {
416+
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
417+
.when(firestoreMock)
418+
.sendRequest(
419+
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
420+
421+
documentReference.set(map(), SetOptions.merge()).get();
422+
423+
assertCommitEquals(
424+
commit(set(Collections.<String, Value>emptyMap(), Collections.<String>emptyList())),
425+
commitCapture.getValue());
426+
}
427+
414428
@Test
415429
public void setDocumentWithNestedMerge() throws Exception {
416430
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)

0 commit comments

Comments
 (0)