Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

LimitOffsetPagination limit=0 fix#3444

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
nhorelik wants to merge5 commits intoencode:masterfromnhorelik:pagination_fix

Conversation

@nhorelik
Copy link

This PR fixes an uncaught ZeroDivisionError I encountered when thelimit query paramater was set to zero when usingrest_framework.pagination.LimitOffsetPagination.

I figured this should return an empty set like you might expect, but otherwise revert to the defaults.

@jpadilla
Copy link
Contributor

@nhorelik there are a few linterissues.

@nhorelik
Copy link
Author

My bad. Serves me right for only pip installingrequirements/requirements-testing.txt instead of the whole thing from the get-go.

Other than what's mentionedhere, do you guys follow/enforce any particular style guide? (for example, thegoogle style guide, or justpep8?)

@jpadilla
Copy link
Contributor

@nhorelik mostly just keeping the linters happy.

@tomchristie@xordoquy thoughts on this? Seems like a valid enhancement to me.

@kevin-brown
Copy link
Contributor

Seems valid, though I feel like this is something which should be handled inget_limit (so it properly defaults).

mitar reacted with thumbs up emoji

@nhorelik
Copy link
Author

If you setself.limit to the default inget_limit,paginate_queryset will not give you an empty result like you might expect from a limit of zero. I figured that this should act like the equivalent sql limit, which meanspaginate_queryset shouldn't use the default limit - it really should be zero there. Since the ZeroDivisionError happens inget_html_context in the calls to_divide_with_ceil at a different time in the flow, I figured it best not to changeself.limit.

If you prefer to treat a limit of zero as an invalid query param and use the defaults for everything including when paginating the queryset, then this is a one-liner fix: just setstrict=True in the call to_positive_int inget_limit.

@xordoquy
Copy link
Contributor

Don't the other paginators considerlimit = 0 to be unlimited ?

mitar reacted with thumbs up emoji

@lovelydinosaur
Copy link
Contributor

We shouldn't allow users to force an unlimited queryset to be returned. Agree that an empty set makes sense.

kevin-brown and iproha94 reacted with thumbs up emoji

@mitar
Copy link
Contributor

I also think that limit=0 should be unlimited (unlimited inside themax_limit limit).
So not providinglimit makes queryset go fordefault_limit, if you providelimit=0, it goes tomax_limit. I think this is reasonable.

@mitar
Copy link
Contributor

I made an alternative fix for this in#3990. By default, iflimit=0 query parameter is provided, it usesmax_limit as effective limit. But this behavior can be changed in a subclass. I think it is a simpler implementation than this one. And allows both desired behaviors for 0.

(Personally, I prefer to usemax_limit because one can already getdefault_limit by simply not providinglimit query parameter.)

@lovelydinosaur
Copy link
Contributor

Closed via#4194

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

3.4.0 Release

Development

Successfully merging this pull request may close these issues.

6 participants

@nhorelik@jpadilla@kevin-brown@xordoquy@lovelydinosaur@mitar

[8]ページ先頭

©2009-2025 Movatter.jp