Skip to content

Commit

Permalink
fix: use correct request type in anon throttle mixin (#4306)
Browse files Browse the repository at this point in the history
  • Loading branch information
DawoudSheraz committed Mar 29, 2024
1 parent fcf25d9 commit df07d96
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions course_discovery/apps/api/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ class AnonymousUserThrottleAuthenticatedEndpointMixin:
See https://github.com/encode/django-rest-framework/issues/5234 for more context.
"""
def dispatch(self, request, *args, **kwargs):
user = request.user
initialized_request = self.initialize_request(request, *args, **kwargs)
user = initialized_request.user
if isinstance(user, AnonymousUser) and (
self.authentication_classes or (self.permission_classes and IsAuthenticated in self.permission_classes)
):
Expand All @@ -194,7 +195,7 @@ def dispatch(self, request, *args, **kwargs):
wait = math.ceil(throttle_instance.wait())
self.args = args
self.kwargs = kwargs
self.request = self.initialize_request(request, *args, **kwargs)
self.request = initialized_request
self.headers = {**self.default_response_headers, 'Retry-After': wait}
self.format_kwarg = self.get_format_suffix(**kwargs)
response = Response(
Expand Down

0 comments on commit df07d96

Please sign in to comment.