spring-data-dynamodb icon indicating copy to clipboard operation
spring-data-dynamodb copied to clipboard

findBy...In results in an exception if argument is an empty collection

Open allan-todd opened this issue 5 years ago • 2 comments

Expected Behavior

Adding the following method to a CrudRepository

List<MyDynamoClass> findByIdIn(Collection<String> id);

and passing in the result of some other process, which happens to be an empyt collection should return and empty list

Actual Behavior

AmazonDynamoDBException occurs

com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: One or more parameter values were invalid: Invalid number of argument(s) for the IN ComparisonOperator (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 40557782-15ed-4636-9338-65adaab7695b)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1660)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1324)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1074)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:745)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:719)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:701)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:669)
	at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:651)
	at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:515)
	at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.doInvoke(AmazonDynamoDBClient.java:3768)
	at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:3737)
	at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.executeScan(AmazonDynamoDBClient.java:2929)
	at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.scan(AmazonDynamoDBClient.java:2897)
	at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.scan(DynamoDBMapper.java:1457)
	at com.amazonaws.services.dynamodbv2.datamodeling.AbstractDynamoDBMapper.scan(AbstractDynamoDBMapper.java:216)
	at org.socialsignin.spring.data.dynamodb.core.DynamoDBTemplate.scan(DynamoDBTemplate.java:128)
	at org.socialsignin.spring.data.dynamodb.query.MultipleEntityScanExpressionQuery.getResultList(MultipleEntityScanExpressionQuery.java:37)
	at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQuery$CollectionExecution.execute(AbstractDynamoDBQuery.java:104)
	at org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQuery.execute(AbstractDynamoDBQuery.java:311)

Steps to Reproduce the Problem

  1. Add a findBy...In method
  2. Call with and empty collection

Specifications

  • Spring Data DynamoDB Version: 5-1-1-SNAPSHOT
  • Spring Data Version: 2-1-4.RELEASE
  • AWS SDK Version: 1.11.415
  • Java Version: 1.8.0_161
  • Platform Details: Windows, DynamoDBLocal

All those information are logged by org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactory on INFO level on startup. Or use java -version and mvn dependency:tree | grep -E 'spring|aws' to provide those version numbers.

allan-todd avatar Apr 10 '19 09:04 allan-todd

Thanks for reporting. Can confirm the issue in org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.withPropertyIn(String, Iterable<?>, Class<?>)

As a workaround: Each Repository has the method Iterable<T> findAllById(Iterable<ID> ids) that does not show this issue. Judging from the attribute name in the example above this might be a feasible alternate method.

derjust avatar May 01 '19 18:05 derjust

Thanks @derjust, yes that workaround works

allan-todd avatar May 08 '19 13:05 allan-todd