CursorPagination previous_link points to an invalid page when a page has no unique markers #7837
Unanswered
jalaziz
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checklist
master
branch of Django REST framework.Steps to reproduce
PAGE_SIZE
setting to 50created
timestamp.created
timestamps.CursorPagination
paginator classExpected behavior
The previous cursor should point back to the first page with 50 results.
Actual behavior
The previous cursor points to a page with 0 results. The next cursor on that page will then point to a page that skips over the records with the same
created
timestamp.Notes
I spent some time investigating this and so far have ended up with two potential issues.
In our exact setup, we have the following distribution of position markers:
After a short investigate, it would appear that the logic that calculates the previous link may be at fault:
{'o': '50'}
✅{'o': '100'}
✅{'r': '1', 'p': '2021-02-01 00:00:00+00:00'}
❌{'p': '2021-02-01 00:00:00+00:00'}
❌The problem seems to occur around here. In our case,
self.next_position
is set2021-02-01 00:00:00+00:00
frompaginate_queryset
.It would seem that when using we're in
offset
territory, theprevious
cursor should effectively point to the previous offset. I do realize that the comments do indicate possible skipping, but the fact that thenext
cursor ends up skipping thereafter is problematic.The problem ultimately occurs because because
paginate_queryset
adds alt
orgt
filter from the cursor position. In the "reverse" case, this returns nothing because the cursor is asking for all records withcreated > '2021-02-01 00:00:00+00:00'
. In the "forward" case, it skips ahead because it asks for all records withcreated < '2021-02-01 00:00:00+00:00'
.I'd be happy to contribute a fix, but I'd like to make sure that this is not expected and get clarity on any edge cases I should consider when fixing the issue. This comment seems to suggest that the skipping back is on purpose. Also, this comment seems to suggest that skipping forward is on purpose. However, is the interaction between the two expected?
Beta Was this translation helpful? Give feedback.
All reactions