Skip to content

Incorrect pagination with predicateFunc in CollectionFilteredPaginate #25665

@pranavjadhav007

Description

@pranavjadhav007

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 item1

Expected Behavior

Same collection and predicate:

// Query: offset=0, limit=1
  Result: ["match-fig"]  // First match

// Query: offset=1, limit=1
  Result: ["match-grape"]  // Second match

Relevant code: https://github.com/cosmos/cosmos-sdk/blob/main/types/query/collections_pagination.go#L64

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