Skip to content
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

Cursor Pagination doesn't play well with query parameters #3328

Closed
CuriousG102 opened this issue Aug 25, 2015 · 3 comments · Fixed by #4260
Closed

Cursor Pagination doesn't play well with query parameters #3328

CuriousG102 opened this issue Aug 25, 2015 · 3 comments · Fixed by #4260

Comments

@CuriousG102
Copy link

The url in next doesn't include the query parameters used in a request, causing 400 bad request responses when using cursor pagination.

@tomchristie
Copy link
Member

Please try to be more specific when raising an issue. Causing a 400 bad request how exactly? What's the smallest possible replicable example?

@CuriousG102
Copy link
Author

Fair enough. I'll put some code up tomorrow or the day after. In the meantime, the most basic example, without code, would be this: There is a model Person with a CharField name. There is a a view that is subclassed off of generics.ListAPIView. This view's get_queryset method is overridden to return people whose name contains a search by a user encoded in a parameter q passed in a get request (i.e. Person.objects.all().filter(Q(name__icontains=self.request.query_params['q']))).

This view is wired up to a url and instantiated with as_view(). Unfortunately, if Cursor Pagination is active (or others, possibly, I have not tested), then the next link will not include the query parameter q. It will only include a parameter for the cursor. This will result in a "400: Bad Request" because there is no query parameter for the search. I don't know if this is a known issue or not. I've already worked around it on my end.

If none of the above is clear, no worries, I'll drop some code to clarify ASAP. Thank you for your work on a truly fantastic product! I have subclassed, used, and read the code repeatedly this past year, for a variety of products. It truly is a life-saver.

@tomchristie
Copy link
Member

Thanks! That should be enough to get started with.

I still don't quite see where/why that'd result in a 400 (I'd expect a KeyError to be raised by your get_queryset() method, instead) but either way the upshot is that CursorPagination should preserve any other query parameters present in the request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants