Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix AttributeError hiding on request authenticators#5600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

rpkilby
Copy link
Member

Fixes#4033. There is an existing test for the issue, however there are a couple of issues:

  • No authentication middleware is used, so therequest.user is never set. Because of this,__getattribute__ will re-raise theAttributeError. However, typical use does include an authentication middleware and will yield auser on the underlying request, as demonstrated bySuppressed AttributeError When Authenticating #4033.
  • TheSessionMiddleware is applied to the DRF request object instead of the underlying Django request, which doesn't mirror how middleware is actually applied.

@rpkilbyrpkilby added this to thev3.7.4 milestoneNov 16, 2017
@rpkilbyrpkilbyforce-pushed thefix-authenticate-attributerror-hiding branch from01f5ef5 tod69f44aCompareNovember 16, 2017 00:56
@rpkilby
Copy link
MemberAuthor

cc @magnus-staberg and@pelme

If you have the time, it would be great if you can verify that this PR fixes#4033 for you.

@rpkilbyrpkilbyforce-pushed thefix-authenticate-attributerror-hiding branch from16ec7ae to746bb17CompareNovember 16, 2017 01:07
# potentially hides AttributeError's raised in `_authenticate`.
if attr in ['user', 'auth']:
raise

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

+1 For not doing this. 🙂

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yep, wanted to demonstrate that this does not work.

Copy link
Collaborator

@carltongibsoncarltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@rpkilby Great stuff!

I think we just need to document the existence ofWrappedAttributeError — the why and what you'd do with it.

A good place for that would be in theCustom Authentication section.

@pelme
Copy link
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 anAttributeError inauthenticate() is enough to trigger it.

Looking at the PR and test I think this PR does the right thing :)

@rpkilbyrpkilbyforce-pushed thefix-authenticate-attributerror-hiding branch from746bb17 toebd1e85CompareNovember 22, 2017 22:05
@rpkilbyrpkilby changed the titleFix request._authenticate AttributError hidingFix request._authenticate AttributeError hidingNov 22, 2017
@rpkilbyrpkilby changed the titleFix request._authenticate AttributeError hidingFix AttributeError hiding on request authenticatorsNov 22, 2017
@carltongibsoncarltongibson merged commitc63e35c intoencode:masterNov 23, 2017
@rpkilbyrpkilby deleted the fix-authenticate-attributerror-hiding branchNovember 23, 2017 07:58
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull requestNov 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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@carltongibsoncarltongibsoncarltongibson approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
3.7.4 Release
Development

Successfully merging this pull request may close these issues.

3 participants
@rpkilby@pelme@carltongibson

[8]ページ先頭

©2009-2025 Movatter.jp