File tree 2 files changed +26
-9
lines changed
2 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 10
10
"""
11
11
from __future__ import unicode_literals
12
12
13
- import sys
14
-
15
13
from django .conf import settings
16
14
from django .http import QueryDict
17
15
from django .http .multipartparser import parse_header
@@ -373,19 +371,15 @@ def _not_authenticated(self):
373
371
else :
374
372
self .auth = None
375
373
376
- def __getattribute__ (self , attr ):
374
+ def __getattr__ (self , attr ):
377
375
"""
378
376
If an attribute does not exist on this instance, then we also attempt
379
377
to proxy it to the underlying HttpRequest object.
380
378
"""
381
379
try :
382
- return super ( Request , self ). __getattribute__ ( attr )
380
+ return getattr ( self . _request , attr )
383
381
except AttributeError :
384
- info = sys .exc_info ()
385
- try :
386
- return getattr (self ._request , attr )
387
- except AttributeError :
388
- six .reraise (info [0 ], info [1 ], info [2 ].tb_next )
382
+ return self .__getattribute__ (attr )
389
383
390
384
@property
391
385
def DATA (self ):
Original file line number Diff line number Diff line change @@ -249,3 +249,26 @@ def test_default_secure_false(self):
249
249
def test_default_secure_true (self ):
250
250
request = Request (factory .get ('/' , secure = True ))
251
251
assert request .scheme == 'https'
252
+
253
+
254
+ class TestWSGIRequestProxy (TestCase ):
255
+ def test_attribute_access (self ):
256
+ wsgi_request = factory .get ('/' )
257
+ request = Request (wsgi_request )
258
+
259
+ inner_sentinel = object ()
260
+ wsgi_request .inner_property = inner_sentinel
261
+ assert request .inner_property is inner_sentinel
262
+
263
+ outer_sentinel = object ()
264
+ request .inner_property = outer_sentinel
265
+ assert request .inner_property is outer_sentinel
266
+
267
+ def test_exception (self ):
268
+ # ensure the exception message is not for the underlying WSGIRequest
269
+ wsgi_request = factory .get ('/' )
270
+ request = Request (wsgi_request )
271
+
272
+ message = "'Request' object has no attribute 'inner_property'"
273
+ with self .assertRaisesMessage (AttributeError , message ):
274
+ request .inner_property
You can’t perform that action at this time.
0 commit comments