-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Open
Description
Problem
The query.CollectionFilteredPaginate function applies the offset to the raw collection before running the predicate filter, instead of applying it to the filtered results. This leads to incorrect pagination when predicate function is used
Current Behavior
Given a collection:
collection := map[string]Item{
"item0": {value: "apple"},
"item1": {value: "banana"},
"item2": {value: "match-fig"},
"item3": {value: "match-grape"}
}
Predicate: strings.HasPrefix(value, "match-")
// Query: offset=0, limit=1
Result: ["match-fig"]
// Query: offset=1, limit=1
Result: ["match-fig"] // Same result! Offset skipped non-matching item1Expected Behavior
Same collection and predicate:
// Query: offset=0, limit=1
Result: ["match-fig"] // First match
// Query: offset=1, limit=1
Result: ["match-grape"] // Second matchRelevant code: https://github.com/cosmos/cosmos-sdk/blob/main/types/query/collections_pagination.go#L64
Metadata
Metadata
Assignees
Labels
No labels