Skip to content

Pagination Issue in DatastoreTemplate queryKeysOrEntities/queryKeysSlice (Cursor Not Set) #4348

@TenorioStephano

Description

@TenorioStephano

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, as it is already mentioned here.

Spring Cloud version 7.4.5

Sample

// More than one record in datastore
assertTrue(datastoreTemplate.queryKeys(query).iterator().hasNext());

// Using queryKeysSlice
Slice<Key> 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());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions