Skip to content

Commit b50c092

Browse files
authored
fix: check for empty before delete (#4047)
spanner IT fails for `deleteAllById_doesNothingOnEmptyIds` test with error from Spanner: `INVALID_ARGUMENT: Failed to initialize transaction due to invalid mutation key.` **Trigger of this behavior change:** spanner activated multiplexed sessions by default in [googleapis/java-spanner#3996](googleapis/java-spanner#3996), which triggers this error. When issuing a write() with a Mutation that has an empty KeySet produces an exception in Multiplexed clients (see [pr](googleapis/java-spanner#4023)), but does a no-op in non-multiplexed ones. Unlike Regular session, multiplex session needs a valid mutation to generate a precommit token. Fixes #4046
1 parent 092a1dd commit b50c092

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

spring-cloud-gcp-data-spanner/src/main/java/com/google/cloud/spring/data/spanner/repository/support/SimpleSpannerRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ public Page<T> findAll(Pageable pageable) {
176176
@Override
177177
public void deleteAllById(Iterable<? extends I> ids) {
178178
Assert.notNull(ids, "IDs must not be null");
179+
if (!ids.iterator().hasNext()) {
180+
return;
181+
}
179182
KeySet.Builder builder = KeySet.newBuilder();
180183
for (Object id : ids) {
181184
builder.addKey(toKey(id));

0 commit comments

Comments
 (0)