Skip to content

Commit d13c807

Browse files
committed
Fix misleading AttributeErrors
1 parent 235b98e commit d13c807

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

rest_framework/request.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from rest_framework import HTTP_HEADER_ENCODING
1919
from rest_framework import exceptions
2020
from rest_framework.settings import api_settings
21+
import sys
2122
import warnings
2223

2324

@@ -485,8 +486,16 @@ def _not_authenticated(self):
485486
else:
486487
self.auth = None
487488

488-
def __getattr__(self, attr):
489+
def __getattribute__(self, attr):
489490
"""
490-
Proxy other attributes to the underlying HttpRequest object.
491+
If an attribute does not exist on this instance, then we also attempt
492+
to proxy it to the underlying HttpRequest object.
491493
"""
492-
return getattr(self._request, attr)
494+
try:
495+
return super(Request, self).__getattribute__(attr)
496+
except AttributeError:
497+
info = sys.exc_info()
498+
try:
499+
return getattr(self._request, attr)
500+
except AttributeError:
501+
raise info[0], info[1], info[2].tb_next

0 commit comments

Comments
 (0)