Skip to content

♻️(backend) remove the unused scope of the document throttles - #2951

Merged
lunika merged 1 commit into
suitenumerique:mainfrom
RoeeSivan:refactor/throttle-scope-2865
Nov 1, 2026
Merged

lunika merged 1 commit into
suitenumerique:mainfrom
RoeeSivan:refactor/throttle-scope-2865

Conversation

@RoeeSivan

Copy link
Copy Markdown
Contributor

Purpose

DocumentThrottle.scope = "document" and DocumentAccessThrottle.scope = "document_access" are never used: DRF's ScopedRateThrottle.allow_request replaces self.scope with the view's throttle_scope before it picks the rate and the cache key. The attributes suggest the classes carry their own scope, while a view that uses them without throttle_scope is not throttled at all.

Closes #2865

Proposal

  • remove the scope attributes of DocumentThrottle and DocumentAccessThrottle
  • say in their docstrings that the scope, and so the rate and the cache key, come from the view's throttle_scope, and that a view without one is not throttled

No behaviour change: DocumentViewSet and DocumentAccessViewSet already set throttle_scope.

No new test. To check that the attributes were dead, I set both to "bogus" on main and ran the existing throttle tests (-k throttl in test_api_throttling_document_throttle.py, test_api_document_accesses.py, test_api_documents_list.py and test_api_documents_media_auth.py): all 9 still pass, and test_api_document_accesses_throttling still reports Rate 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

  • Before submitting a PR for a new feature I made sure to contact the product manager

CI requirements

  • I made sure that all existing tests are passing
  • I have signed off my commits with git commit --signoff (DCO compliance)
  • I have signed my commits with my SSH or GPG key (git commit -S)
  • My commit messages follow the required format: <gitmoji>(type) title description
  • I have added a changelog entry under ## [Unreleased] section (if noticeable change)

AI requirements

Skip the checkboxes below 👇 If you didn't use AI for your contribution

  • I used AI assistance to produce part or all of this contribution
  • I have read, reviewed, understood and can explain the code I am submitting
  • I can jump in a call or a chat to explain my work to a maintainer

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]>
@RoeeSivan
RoeeSivan force-pushed the refactor/throttle-scope-2865 branch from 7b350d6 to 8a7b43c Compare October 31, 2026 20:45
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 23a8ec8e-1fe3-41a0-9e5c-cad35fe08766
Commits

Reviewing files that changed from the base of the PR and between 489c7d4 and 8a7b43c.

Files selected for processing: 2
  • CHANGELOG.md
  • src/backend/core/api/throttling.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

DocumentThrottle and DocumentAccessThrottle no longer define fixed scopes. Their docstrings state that the view’s throttle_scope supplies the scope, rate, and cache key, and that views without one are not throttled. The changelog records the change.

Estimated code review effort: 2 (Simple) | ~8 minutes

Suggested reviewers: lunika

Merge Risk: Minimal · up to 8a7b4

The cleanup preserves document throttling behavior and accurately documents view-owned scopes. No merge-blocking issue remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the main change: removing the unused scope attributes from the document throttles. The changeset removes DocumentThrottle.scope and DocumentAccessThrottle.scope and updates their docst…
Description check Passed The description explains why the scope attributes are dead code. DRF's ScopedRateThrottle replaces self.scope with the view's throttle_scope. It lists the proposed changes (removing the attributes, up…
Linked Issues check Passed Issue #2865 requires removal of the unused class-level scopes and documentation of the view-controlled scope, rate, and cache key. The diff removes both scope attributes from DocumentThrottle and …
Out of Scope Changes check Passed The changes are limited to the two throttle declarations and one changelog entry. The docstring updates and changelog entry directly document the change requested by issue #2865. No unrelated implemen…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check

Explanation

The title names the main change: removing the unused scope attributes from the document throttles. The changeset removes DocumentThrottle.scope and DocumentAccessThrottle.scope and updates their docstrings, so the title matches the primary change.

Full details: Description check

Explanation

The description explains why the scope attributes are dead code. DRF's ScopedRateThrottle replaces self.scope with the view's throttle_scope. It lists the proposed changes (removing the attributes, updating docstrings) and describes the testing done. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

Issue #2865 requires removal of the unused class-level scopes and documentation of the view-controlled scope, rate, and cache key. The diff removes both scope attributes from DocumentThrottle and DocumentAccessThrottle. Their docstrings state that throttle_scope supplies the scope, rate, and cache key, and that a view without it is not throttled.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the two throttle declarations and one changelog entry. The docstring updates and changelog entry directly document the change requested by issue #2865. No unrelated implementation changes are shown.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@lunika
lunika enabled auto-merge (squash) November 1, 2026 16:49
@lunika

lunika commented Nov 1, 2026

Copy link
Copy Markdown
Member

Thanks again for your contribution.

@lunika
lunika merged commit ad29f64 into suitenumerique:main Nov 1, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

♻️(refacto) Unused scope attributes on DocumentThrottle and DocumentAccessThrottle

2 participants