Skip to content

Commit 112b25c

Browse files
Revert "Allowing empty merges" (#2965)
1 parent 3ea00d1 commit 112b25c

3 files changed

Lines changed: 6 additions & 21 deletions

File tree

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,6 +245,7 @@ private T performSet(
245245
DocumentTransform.fromFieldPathMap(documentReference, documentData);
246246

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

257258
Mutation mutation = addMutation();
258259

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

google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java

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

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

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

google-cloud-firestore/src/test/java/com/google/cloud/firestore/DocumentReferenceTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,6 @@ 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-
428414
@Test
429415
public void setDocumentWithNestedMerge() throws Exception {
430416
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)

0 commit comments

Comments
 (0)