-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Demo and fix broken pagination #7889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3ee55cd
to
6bcd2f8
Compare
6bcd2f8
to
75dc267
Compare
75dc267
to
9408b43
Compare
assert next is None | ||
assert previous_url is not None | ||
assert next_url is None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was a bit too complicated to test with the MockQueryset
.
tests/test_pagination.py
Outdated
@@ -884,7 +919,7 @@ def test_cursor_pagination_with_page_size_negative(self): | |||
|
|||
assert previous == [4, 4, 5, 6, 7] | |||
assert current == [7, 7, 7, 7, 7] | |||
assert next == [8, 9, 9, 9, 9] # Paging artifact | |||
#assert next == [8, 9, 9, 9, 9] # Paging artifact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure these 'paging artefacts' have been fixed by this.
tests/test_pagination.py
Outdated
|
||
return _statements | ||
|
||
return lambda item: operator_map[q_object.connector](l(item) for l in _parse(q_object)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a massive fan of 'MockQuerysets' because we're really reimplementing stuff that's handled by the database. But I tried to keep the pattern of tests as they are.
2f7acbf
to
29d8796
Compare
Okay, so this PR falls a long way into our "no" territory. You've spent time and care on this, so I'll try to help explain some of why our outlook on this as maintainers differs to yours.
So, the pull request doesn't demonstrate much to me because it's a ~430 line pull request that'd require a huge amount of time to fully review, for a use case that doesn't really meet the documented constraints of the CursorPagination. To give some contrast, here's a one-liner pull request, that seemed pretty reasonable (use deque instead of list, for performance reasons) which we accepted, and then reverted once it turned out that it actually broke some existing usages for unexpected reasons. Consider the amount of time we need to spend in order to fully assess if a one line pull request, with a clear motivation. Then contrast it with what's being requested here. I'd hope that'd help make it more clear that large scoped pull requests like this just aren't realistic, particularly when the motivation and understanding of the trade-offs it introduces haven't first been adequately addressed in discussion. If you're invested in putting time into this, then the best route is as a third party package, which we would then link to from the main docs... https://www.django-rest-framework.org/api-guide/pagination/#third-party-packages |
@tomchristie I get that it is a little bit subtle and doesn't happen in all cases; while I also understand that you probably have 100s of inexperienced developers vying for your time who have no idea what they're doing. I know this stuff is taxing to read. As per the project guidelines, I submitted a pull request, first with the failing test, then another commit with the fix. I even linked the individual commits (for the problem, and the fix). But I don't think anyone even took the time to examine how it's broken (because it is hard work and people have priorities). I feel that I've received a knee-jerk response that's essentially: it's not a problem; and that even if it was, it is not; and that I should read the documentation. I totally get the tedium of managing a package that's used by thousands, and how APIs are fragile. I've managed packages too. However, it would have been nice to at least have had the reaction "yes this is bug, but we can't fix it because of x". With the utmost respect, I'm actually working on a project that you previously consulted on, and this is an edge case that I think you were personally caught out by (and partly why I felt that I should contribute back). If there's no recognition that is a 'wontfix' or a 'bug', what's the point in me making a 3rd party package? Someone might encounter this issue, but all they'll see is two maintainers denying this is a problem. If it would help, I'm more than happy to spend more time trying to make a shorter pull request that reduces the number of testing changes. I'm also more than happy to jump of a meets/zoom/skype etc to pair with you to help bring you through the problem. The only reason that I added more commits was that my change broke the old tests (because the tests seem to both run as mocks and with real objects). Because I was told that I was 'using it wrong' and not reading the documentation, I started to doubt myself, and spent a few hours verifying that my change was in fact okay. I haven't meaningfully changed the tests. In fact I think I fixed a few subtle bugs that are labeled 'paging artefact'. |
Ok noted. I'm too busy to have a second look over this right now, but can take a re-review next week sometime. I guess the helpful thing from my POV would be starting with an absolutely minimal PR, that demonstrates a breakage with as absolutely small a change footprint as possible. (Although I realise that's asking for more work on your side) |
Thanks @tomchristie, I really appreciate that. I apologise for getting frustrated there. I also understand that contributing to open source takes time, and that problems often languish for months before they can be merged In regards to the breakage, I tried to keep it small (while being comprehensive). There's only one test there, I just I would be able to write clearer code if the problem was encapsulated in a single file. But I'll try and condense it down ASAP into test_pagination.py. Personally, I think it's worth at least investigating further. Paginated endpoints are often critical for clients who want to fetch all of their data, and a breakage particularly in that use case can have major consequences for businesses. |
Originally discussed in #7888
This demonstrates how the pagination is broken if someone tries to order by
non_unique_field,id
. The only case where it does work is when the offset_cutoff is the same as the page_size.