In a custom authentication backend, I was getting this error with this (previous developer's!) code:
if user.is_authenticated() and user.is_staff:
AttributeError: 'NoneType' object has no attribute 'is_authenticated'
The cause seemed clear, the parent classes method was run first with super and returned None when it failed to authenticate, so I tried to fix by testing whether user is None, but I still get this:
if (user is not None) and user.is_authenticated() and user.is_staff:
AttributeError: 'NoneType' object has no attribute 'is_authenticated'
I am probably missing something obvious, but if user is None, only (user is not None) will be evaluated there should be no error, if user is not None, I should not have a NoneType in the error.