Fix AttributeError hiding on request authenticators#5600
Merged
carltongibson merged 6 commits intoencode:masterfrom Nov 23, 2017
Merged
Fix AttributeError hiding on request authenticators#5600carltongibson merged 6 commits intoencode:masterfrom
carltongibson merged 6 commits intoencode:masterfrom
Conversation
This was referenced Nov 16, 2017
01f5ef5 to
d69f44a
Compare
Contributor
Author
16ec7ae to
746bb17
Compare
| # potentially hides AttributeError's raised in `_authenticate`. | ||
| if attr in ['user', 'auth']: | ||
| raise | ||
|
|
Collaborator
There was a problem hiding this comment.
+1 For not doing this. 🙂
Contributor
Author
There was a problem hiding this comment.
Yep, wanted to demonstrate that this does not work.
carltongibson
requested changes
Nov 22, 2017
Collaborator
carltongibson
left a comment
There was a problem hiding this comment.
@rpkilby Great stuff!
I think we just need to document the existence of WrappedAttributeError — the why and what you'd do with it.
A good place for that would be in the Custom Authentication section.
Contributor
|
@rpkilby we cannot really reproduce it now any more since our code has fixed the AttributeError and changed quite a bit since we originally reported this. But yes, just raising an Looking at the PR and test I think this PR does the right thing :) |
746bb17 to
ebd1e85
Compare
carltongibson
approved these changes
Nov 23, 2017
pchiquet
pushed a commit
to pchiquet/django-rest-framework
that referenced
this pull request
Nov 17, 2020
* 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4033. There is an existing test for the issue, however there are a couple of issues:
request.useris never set. Because of this,__getattribute__will re-raise theAttributeError. However, typical use does include an authentication middleware and will yield auseron the underlying request, as demonstrated by Suppressed AttributeError When Authenticating #4033.SessionMiddlewareis applied to the DRF request object instead of the underlying Django request, which doesn't mirror how middleware is actually applied.