You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix AttributeError hiding on request authenticators (#5600)
* Update assertion style in user logout test
* Apply middlewares to django request object
* Fix test for request auth hiding AttributeErrors
* Re-raise/wrap auth attribute errors
* Fix test for py2k
* Add docs for WrappedAttributeError
Copy file name to clipboardExpand all lines: docs/api-guide/authentication.md
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -291,6 +291,12 @@ You *may* also override the `.authenticate_header(self, request)` method. If im
291
291
292
292
If the `.authenticate_header()` method is not overridden, the authentication scheme will return `HTTP 403 Forbidden` responses when an unauthenticated request is denied access.
293
293
294
+
---
295
+
296
+
**Note:** When your custom authenticator is invoked by the request object's `.user` or `.auth` properties, you may see an `AttributeError` re-raised as a `WrappedAttributeError`. This is necessary to prevent the original exception from being suppressed by the outer property access. Python will not recognize that the `AttributeError` orginates from your custom authenticator and will instead assume that the request object does not have a `.user` or `.auth` property. These errors should be fixed or otherwise handled by your authenticator.
297
+
298
+
---
299
+
294
300
## Example
295
301
296
302
The following example will authenticate any incoming request as the user given by the username in a custom request header named 'X_USERNAME'.
Copy file name to clipboardExpand all lines: docs/api-guide/requests.md
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -90,6 +90,10 @@ You won't typically need to access this property.
90
90
91
91
---
92
92
93
+
**Note:** You may see a `WrappedAttributeError` raised when calling the `.user` or `.auth` properties. These errors originate from an authenticator as a standard `AttributeError`, however it's necessary that they be re-raised as a different exception type in order to prevent them from being suppressed by the outer property access. Python will not recognize that the `AttributeError` orginates from the authenticator and will instaed assume that the request object does not have a `.user` or `.auth` property. The authenticator will need to be fixed.
94
+
95
+
---
96
+
93
97
# Browser enhancements
94
98
95
99
REST framework supports a few browser enhancements such as browser-based `PUT`, `PATCH` and `DELETE` forms.
0 commit comments