Changes between Initial Version and Version 2 of Ticket #26988
- Timestamp:
- Aug 2, 2016, 5:38:10 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #26988
- Property Summary User is_authenticated callable property confusing if used with "is False" → User is_authenticated callable property is confusing to check
- Property Easy pickings set
-
Ticket #26988 – Description
initial v2 1 Just upgraded to 1.10, converted all {{{ is_authenticated() }}} methods into {{{ is_authenticated}}} properties as per the [https://docs.djangoproject.com/en/1.10/releases/1.10/#using-user-is-authenticated-and-user-is-anonymous-as-methods Release Notes] and a test in my test suite failed.1 Just upgraded to 1.10, converted all {{{is_authenticated()}}} methods into {{{is_authenticated}}} properties as per the [https://docs.djangoproject.com/en/1.10/releases/1.10/#using-user-is-authenticated-and-user-is-anonymous-as-methods Release Notes] and a test in my test suite failed. 2 2 3 It turns out I was checking for a logged in user with {{{ if request.user.is_authenticated is False: }}}, but the {{{ is_authenticated }}} property is actually a {{{ CallableBool() }}} so is not False under any circumstances.3 It turns out I was checking for a logged in user with {{{if request.user.is_authenticated is False:}}}, but the {{{is_authenticated}}} property is actually a {{{CallableBool}}} which cannot be tested with {{== False}}, {{is False}}, {{== True}} or {{is True}}. 4 4 5 Checking this property only gives logical results with direct {{{ if user.is_authenticated }}} or {{{ if not user.is_authenticated }}}. This is very misleading and non-intuitive behaviourand should be fixed or strongly called out in the documentation. Example:5 Checking this property only gives logical results with direct {{{if user.is_authenticated}}} or {{{if not user.is_authenticated}}}. This is very misleading and non-intuitive behaviour (at odds with [https://www.python.org/dev/peps/pep-0008/#programming-recommendations PEP8 (bottom of linked section)] and should be fixed or strongly called out in the documentation. Example: 6 6 7 7 {{{