GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp
Pagination Issue in DatastoreTemplate queryKeysOrEntities/queryKeysSlice (Cursor Not Set)
- Dominant language
- Java
- Stars
- 551
- Forks
- 349
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 14
Description
**Description**
`DatastoreTemplate` methods `queryKeysSlice`/`queryKeysOrEntities` do not iterate over results, and because of that, the cursor is not populated.
The results should be iterated in this [reference](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/blob/87153c1150d0a5e2d981b91941177f6dfd010a51/spring-cloud-gcp-data-datastore/src/main/java/com/google/cloud/spring/data/datastore/core/DatastoreTemplate.java#L359C15-L359C15), as it is already mentioned [here](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/blob/87153c1150d0a5e2d981b91941177f6dfd010a51/spring-cloud-gcp-data-datastore/src/main/java/com/google/cloud/spring/data/datastore/core/DatastoreTemplate.java#L387).
Spring Cloud version `7.4.5`
**Sample**
```
// More than one record in datastore
assertTrue(datastoreTemplate.queryKeys(query).iterator().hasNext());
// Using queryKeysSlice
Slice results = datastoreTemplate.queryKeysSlice(query, Key.class, Pageable.ofSize(1));
assertTrue(results.hasNext());
assertInstanceOf(DatastorePageable.class, results.nextPageable());
assertTrue(((DatastorePageable) results.nextPageable()).getUrlSafeCursor().isEmpty()); // Should not be empty
// Using queryKeysOrEntities
KeyQuery queryWithLimit = query.toBuilder().setLimit(1).build();
var objects = datastoreTemplate.queryKeysOrEntities(queryWithLimit, Key.class);
assertTrue(objects.getCursor().toUrlSafe().isEmpty()); // Should not be empty
// Workaround to use cursor with Key class
objects = datastoreTemplate.queryIterable(query, Function.identity());
assertFalse(objects.getCursor().toUrlSafe().isEmpty());
```
Contributor guide
Assessment
This issue has not been assessed yet.