Opened 5 years ago
Last modified 5 years ago
#30941 closed Bug
hasattr(request, '_cached_user') check no longer works — at Version 2
Reported by: | Collin Anderson | Owned by: | nobody |
---|---|---|---|
Component: | contrib.auth | Version: | dev |
Severity: | Release blocker | Keywords: | |
Cc: | cmawebsite@…, Sergey Fedoseev, Simon Charette | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Before https://github.com/django/django/commit/2f01079, it was possible to check to see whether the lazy user has been evaluated or not using hasattr(request, '_cached_user')
. This was undocumented, but used a lot: https://github.com/search?q=hasattr%28request%2C+%27_cached_user%27%29&type=Code
I think we should try to maintain backwards compatibility for that that check, and document and test it for the future. (Or if nothing else, document and test the new behavior and add a release note about the change.)
This is really helpful in middleware to be able to check this, so you can access the user if it has already been accessed, but can avoid fetching user if it hasn't already been fetched.
Change History (2)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|
comment:2 by , 5 years ago
Description: | modified (diff) |
---|