Skip to content

RATELIMIT_VIEW Not Functioning as Expected with Class-Based Views #315

@Aryancsz

Description

@Aryancsz

Issue Description

When applying the @method_decorator(ratelimit(key="user", rate="2/h", block=True), name="change_password") decorator to a method within a class-based view, the custom error message defined in RATELIMIT_VIEW is not being thrown. However, when the same decorator is applied to a function-based view, it works as expected.

Steps to Reproduce

  1. Define a class-based view with a method decorated with @method_decorator(ratelimit(key="user", rate="2/h", block=True), name="change_password").
  2. Ensure RATELIMIT_VIEW is properly defined with a custom error message.
  3. Attempt to trigger the rate limit by invoking the method.

Expected Behavior

The custom error message defined in RATELIMIT_VIEW should be thrown when the rate limit is exceeded, regardless of whether the view is class-based or function-based.

Actual Behavior

The custom error message is not thrown ( does throw permission denied ) when the rate limit is exceeded in a class-based view, while it works correctly in a function-based view.

Additional Information

  • Package version: 4.1.0

Workarounds Tried

  • Applying the decorator directly to URLs or the entire class view and it worked but resulted in loss of flexibility for different methods.

Note: This issue affects the flexibility and consistency of rate limiting in class-based views compared to function-based views.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions