From 8950f183a9adb58f50f23f756822df00329959d7 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Wed, 22 Nov 2017 17:47:44 -0500 Subject: [PATCH] Add docs for WrappedAttributeError --- docs/api-guide/authentication.md | 6 ++++++ docs/api-guide/requests.md | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/docs/api-guide/authentication.md b/docs/api-guide/authentication.md index a7a24029b..63a789dfc 100644 --- a/docs/api-guide/authentication.md +++ b/docs/api-guide/authentication.md @@ -291,6 +291,12 @@ You *may* also override the `.authenticate_header(self, request)` method. If im If the `.authenticate_header()` method is not overridden, the authentication scheme will return `HTTP 403 Forbidden` responses when an unauthenticated request is denied access. +--- + +**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. + +--- + ## Example The following example will authenticate any incoming request as the user given by the username in a custom request header named 'X_USERNAME'. diff --git a/docs/api-guide/requests.md b/docs/api-guide/requests.md index 393b1ab9a..83a38d1c3 100644 --- a/docs/api-guide/requests.md +++ b/docs/api-guide/requests.md @@ -90,6 +90,10 @@ You won't typically need to access this property. --- +**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. + +--- + # Browser enhancements REST framework supports a few browser enhancements such as browser-based `PUT`, `PATCH` and `DELETE` forms.