From 1e8c2c895898818a4c455c8b1bb5da20c78cd491 Mon Sep 17 00:00:00 2001 From: DawoudSheraz Date: Thu, 28 Mar 2024 23:07:48 +0500 Subject: [PATCH] fix: use correct request type in anon throttle mixin --- course_discovery/apps/api/mixins.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/course_discovery/apps/api/mixins.py b/course_discovery/apps/api/mixins.py index 53aa5ce43e..11dfc21db6 100644 --- a/course_discovery/apps/api/mixins.py +++ b/course_discovery/apps/api/mixins.py @@ -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) ): @@ -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(