Forums

AttributeError: 'bool' object has no attribute 'is_authenticated'

I get a very wierd error from Flask_login, namely AttributeError: 'bool' object has no attribute 'is_authenticated'

Has anyone seen this before? The strange thing is that it doesn't seem to say where in my code it went wrong. I am using Flask_sqlalchemy and this happened when I dropped the user table and recreated it.

Here is the full relevant stack trace

2018-04-02 15:57:16,267: Error running WSGI application
2018-04-02 15:57:16,275: AttributeError: 'bool' object has no attribute 'is_authenticated'
2018-04-02 15:57:16,276:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 2000, in __call__
2018-04-02 15:57:16,276:     return self.wsgi_app(environ, start_response)
2018-04-02 15:57:16,276: 
2018-04-02 15:57:16,277:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1991, in wsgi_app
2018-04-02 15:57:16,277:     response = self.make_response(self.handle_exception(e))
2018-04-02 15:57:16,277: 
2018-04-02 15:57:16,277:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1567, in handle_exception
2018-04-02 15:57:16,279:     reraise(exc_type, exc_value, tb)
2018-04-02 15:57:16,279: 
2018-04-02 15:57:16,279:   File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
2018-04-02 15:57:16,279:     raise value
2018-04-02 15:57:16,279: 
2018-04-02 15:57:16,279:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1988, in wsgi_app
2018-04-02 15:57:16,279:     response = self.full_dispatch_request()
2018-04-02 15:57:16,280: 
2018-04-02 15:57:16,280:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1641, in full_dispatch_request
2018-04-02 15:57:16,280:     rv = self.handle_user_exception(e)
2018-04-02 15:57:16,281: 
2018-04-02 15:57:16,281:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1544, in handle_user_exception
2018-04-02 15:57:16,281:     reraise(exc_type, exc_value, tb)
2018-04-02 15:57:16,281: 
2018-04-02 15:57:16,281:   File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
2018-04-02 15:57:16,282:     raise value
2018-04-02 15:57:16,283: 
2018-04-02 15:57:16,283:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1639, in full_dispatch_request
2018-04-02 15:57:16,283:     rv = self.dispatch_request()
2018-04-02 15:57:16,283: 
2018-04-02 15:57:16,283:   File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1625, in dispatch_request
2018-04-02 15:57:16,284:     return self.view_functions[rule.endpoint](**req.view_args)
2018-04-02 15:57:16,284: 
2018-04-02 15:57:16,284:   File "/usr/local/lib/python3.5/dist-packages/flask_login.py", line 790, in decorated_view
2018-04-02 15:57:16,284:     elif not current_user.is_authenticated:
2018-04-02 15:57:16,284: 
2018-04-02 15:57:16,284:   File "/usr/local/lib/python3.5/dist-packages/werkzeug/local.py", line 343, in __getattr__
2018-04-02 15:57:16,284:     return getattr(self._get_current_object(), name)

if you dropped the user table, but not other tables, your website is probably confused when say it gets the session data and tries to access the user. and the current_user.is_authenticated line is failing probably because the current user doesn't exist.

if you don't have any important live data/users, maybe just completely drop all the tables and recreate them?

Hello and thanks for your feedback.

This happens when I delete the database all together and restart the app. But it still seems that some cookie is left in the session which makes the thing confused.

From the traceback, I'm guessing it's an issue with the flask_login package. Perhaps you can take it up with the authors.