Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute check in CurrentUserMiddleware._del_user? #4

Open
vbudovski-alliance opened this issue Jan 25, 2021 · 5 comments
Open

Attribute check in CurrentUserMiddleware._del_user? #4

vbudovski-alliance opened this issue Jan 25, 2021 · 5 comments

Comments

@vbudovski-alliance
Copy link
Contributor

Is there any reason to not check for the presence of user attribute on GLOBAL_USER before deleting?

@fanglong-alliance
Copy link
Contributor

ah, i was about to raise this again.

current user middleware suppresses other errors (duh)
cause:
_del_user gets called multiple times if exception occurs, process_exception deletes it then process_response tries to delete again
this triggers its own exception and suppressed the original, actual error

@fanglong-alliance
Copy link
Contributor

damn and still here lol

@levic
Copy link

levic commented Oct 3, 2022

  • If CurrentUserMiddleware is included twice in the middleware list then you'll also get the same symptom. This is an error and should be flagged instead of ignored.
  • If an internal django sub-request is created, then I'm not sure what happens with threading.local() (does django ensure that new local thread storage is created or is it inherited from the original request?) If it's simply inherited then the user will be (erroneously) wiped by the sub-request.

Rather than simply checking for the attribute before clearing these really should have test coverage (of the above 2 situations, and the case where there's an exception) so that we know that it's actually doing what it's supposed to be.

@davecoates is it possible to allocate some time for someone to look at this?

@davecoates
Copy link
Contributor

yep will do

@levic
Copy link

levic commented May 15, 2023

Related: if changes are made here then we probably should also change it to support async: https://peps.python.org/pep-0567/ (TLDR: use contextvars.ContextVar instead of threading.local)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants