Skip to content

Use getattr for better performance #4011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion rest_framework/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,24 @@ def _not_authenticated(self):
else:
self.auth = None

def __getattribute__(self, attr):
def __getattr__(self, attr):
"""
If an attribute does not exist on this instance, then we also attempt
to proxy it to the underlying HttpRequest object.
"""
try:
return getattr(self._request, attr)
except AttributeError:
# Call the original implementation of getattribute
# So the correct attribute error will get raised
self.__getattr_trace__(attr)

def __getattr_trace__(self, attr):
"""
The original implementation of __getattribute__ which
generates correct tracebacks
See #2108 and #2530
"""
try:
return super(Request, self).__getattribute__(attr)
except AttributeError:
Expand Down