diff options
| author | Tom Christie | 2015-02-09 17:02:54 +0000 |
|---|---|---|
| committer | Tom Christie | 2015-02-09 17:02:54 +0000 |
| commit | d13c807616030b285589cec2fddf4e34a8e22b4a (patch) | |
| tree | 73f2cf97cb90d1387ef61fec8658c3896eebcb73 | |
| parent | 235b98e427e2bae2b52fb386a42c8045724de251 (diff) | |
| download | django-rest-framework-d13c807616030b285589cec2fddf4e34a8e22b4a.tar.bz2 | |
Fix misleading AttributeErrors
| -rw-r--r-- | rest_framework/request.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/rest_framework/request.py b/rest_framework/request.py index cfbbdecc..38fcf9c0 100644 --- a/rest_framework/request.py +++ b/rest_framework/request.py @@ -18,6 +18,7 @@ from django.utils.six import BytesIO from rest_framework import HTTP_HEADER_ENCODING from rest_framework import exceptions from rest_framework.settings import api_settings +import sys import warnings @@ -485,8 +486,16 @@ class Request(object): else: self.auth = None - def __getattr__(self, attr): + def __getattribute__(self, attr): """ - Proxy other attributes to the underlying HttpRequest object. + If an attribute does not exist on this instance, then we also attempt + to proxy it to the underlying HttpRequest object. """ - return getattr(self._request, attr) + try: + return super(Request, self).__getattribute__(attr) + except AttributeError: + info = sys.exc_info() + try: + return getattr(self._request, attr) + except AttributeError: + raise info[0], info[1], info[2].tb_next |
