This way it'll be possible to check if the user is authenticated by simply
writing
{{{
if request.user:
}}}
It's a frequent source of bugs (at least for me, but probably I'm not
alone) that right now this code returns True for anonymous users.
--
Ticket URL: <https://code.djangoproject.com/ticket/28259>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Tim Graham):
The Django test suite passes with the change but I feel like that could
have some backwards compatibility concerns. Also "explicit is better than
implicit"? You could write to the DevelopersMailingList to get other
opinions.
--
Ticket URL: <https://code.djangoproject.com/ticket/28259#comment:1>
* status: new => closed
* resolution: => wontfix
Comment:
[https://groups.google.com/d/topic/django-
developers/rGWdttZO06g/discussion django-developers discussion]
Closing for now as Adam's reply on the mailing list confirms my intuition:
"We already have if `request.user.is_authenticated` and
`request.user.is_anonymous` which are both more explicit and pythonic.
Additionally all python classes, and thus instances of User atm, are by
default truthy, so implementing this custom `__bool__` introduces space
for more subtle bugs, e.g. the result of `filter([request.user])` would
change."
--
Ticket URL: <https://code.djangoproject.com/ticket/28259#comment:2>
Comment (by sureshvv):
request.user.is_authenticated and request.user.is_anonymous
too verbose to check a boolean attribute. Totally "unpythonic".
--
Ticket URL: <https://code.djangoproject.com/ticket/28259#comment:3>