Repository navigation
♻️(backend) remove the unused scope of the document throttles - #2951
Conversation
DRF's ScopedRateThrottle replaces self.scope with the view's throttle_scope before it picks the rate and the cache key, so the scope set on DocumentThrottle and DocumentAccessThrottle was never used. It also suggested that the classes throttle on their own, while a view without throttle_scope is not throttled at all. Say in the docstrings where the scope comes from instead. Closes suitenumerique#2865 Signed-off-by: Roee Sivan <[email protected]>
7b350d6 to
8a7b43c
Compare
|
No actionable comments were generated in the recent review.
|
|
Thanks again for your contribution. |
Purpose
DocumentThrottle.scope = "document"andDocumentAccessThrottle.scope = "document_access"are never used: DRF'sScopedRateThrottle.allow_requestreplacesself.scopewith the view'sthrottle_scopebefore it picks the rate and the cache key. The attributes suggest the classes carry their own scope, while a view that uses them withoutthrottle_scopeis not throttled at all.Closes #2865
Proposal
scopeattributes ofDocumentThrottleandDocumentAccessThrottlethrottle_scope, and that a view without one is not throttledNo behaviour change:
DocumentViewSetandDocumentAccessViewSetalready setthrottle_scope.No new test. To check that the attributes were dead, I set both to
"bogus"onmainand ran the existing throttle tests (-k throttlintest_api_throttling_document_throttle.py,test_api_document_accesses.py,test_api_documents_list.pyandtest_api_documents_media_auth.py): all 9 still pass, andtest_api_document_accesses_throttlingstill reportsRate limit exceeded for scope document_access. These tests keep covering both scopes after the change.External contributions
Thank you for your contribution! 🎉
Please ensure the following items are checked before submitting your pull request:
General requirements
Skip the checkbox below 👇 if you're fixing an issue or adding documentation
CI requirements
git commit --signoff(DCO compliance)git commit -S)<gitmoji>(type) title description## [Unreleased]section (if noticeable change)AI requirements
Skip the checkboxes below 👇 If you didn't use AI for your contribution