Duplicated and missing items when using GraphQL API with sorting and pagination. #18727
Labels
issue: bug
Issue reporting a bug
severity: low
If the issue only affects a very niche base of users and an easily implemented workaround can solve
source: core:database
Source is core/database package
source: plugin:graphql
Source is plugin/graphql package
status: confirmed
Confirmed by a Strapi Team member or multiple community members
Bug report
Warning: this bug is NOT a duplicate of #11892, though, it might be related to the same issue. It might also be a bug in Postgres.
Fix: This bug can be worked around by adding "id" or another unique attribute to the end of the sorting args array.
For example:
sort: "name"
should be changed tosort: ["name", "id"]
. This fixes the problem. More details at the end of the report.Required System information
Describe the bug
When using pagination with sorting via the GraphQL API, one row appears on two pages, while another row doesn't appear at all.
Steps to reproduce the behavior
Expected behavior
Accumulated results from requesting all pages via GraphQL should be a list containing every row once.
Code snippets
Sorry for my absolutely random test data, I have censored out the swear words.
JSON response of all items when requested as a single page:
Accumulated response data from 3 requests with page size = 8:
The bug only happens when the sorting order is ambiguous across the end of a page. This occurs when the last element on one page and the first element on another have the same value of the sorting arg, (in this case, the "name" field). Adding at least one unique attribute to the sorting arg fixes the problem.
The text was updated successfully, but these errors were encountered: