Skip to content

Commit 46e09aa

Browse files
authored
fix: Allow an explicit MustExist precondition for update (#1542)
1 parent ead5e14 commit 46e09aa

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

google-cloud-firestore/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
<dependency>
159159
<groupId>com.google.cloud</groupId>
160160
<artifactId>google-cloud-conformance-tests</artifactId>
161-
<version>0.3.6</version>
161+
<version>0.3.7</version>
162162
<scope>test</scope>
163163
<exclusions>
164164
<exclusion>

google-cloud-firestore/src/main/java/com/google/cloud/firestore/Precondition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ boolean isEmpty() {
6262
return exists == null && updateTime == null;
6363
}
6464

65-
boolean hasExists() {
66-
return exists != null;
65+
Boolean getExists() {
66+
return exists;
6767
}
6868

6969
com.google.firestore.v1.Precondition toPb() {

google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ public T update(
387387
@Nonnull Map<String, Object> fields,
388388
Precondition precondition) {
389389
Preconditions.checkArgument(
390-
!precondition.hasExists(), "Precondition 'exists' cannot be specified for update() calls.");
390+
!Boolean.FALSE.equals(precondition.getExists()),
391+
"Precondition 'exists' cannot have the value 'false' for update() calls.");
391392
return performUpdate(
392393
documentReference, convertToFieldPaths(fields, /* splitOnDots= */ true), precondition);
393394
}
@@ -455,7 +456,8 @@ public T update(
455456
@Nullable Object value,
456457
Object... moreFieldsAndValues) {
457458
Preconditions.checkArgument(
458-
!precondition.hasExists(), "Precondition 'exists' cannot be specified for update() calls.");
459+
!Boolean.FALSE.equals(precondition.getExists()),
460+
"Precondition 'exists' cannot have the value 'false' for update() calls.");
459461
return performUpdate(
460462
documentReference,
461463
precondition,
@@ -483,7 +485,8 @@ public T update(
483485
@Nullable Object value,
484486
Object... moreFieldsAndValues) {
485487
Preconditions.checkArgument(
486-
!precondition.hasExists(), "Precondition 'exists' cannot be specified for update() calls.");
488+
!Boolean.FALSE.equals(precondition.getExists()),
489+
"Precondition 'exists' cannot have the value 'false' for update() calls.");
487490
return performUpdate(documentReference, precondition, fieldPath, value, moreFieldsAndValues);
488491
}
489492

0 commit comments

Comments
 (0)