Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'bool' object is not callable #74

Closed
jerrypy opened this issue Sep 16, 2015 · 15 comments
Closed

TypeError: 'bool' object is not callable #74

jerrypy opened this issue Sep 16, 2015 · 15 comments

Comments

@jerrypy
Copy link

jerrypy commented Sep 16, 2015

I followed your book to learn flask, it works very well until I used current_user , I got

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

this kind of error. I thought maybe there're some mistakes in my code, so I download your code from github, and checkout to branch 8c, but same thing happend, check traceback message below:

root@fb-kali:/opt/flasky# python manage.py runserver --port 8888 --host 0.0.0.0 --debug
 * Running on http://0.0.0.0:8888/
 * Restarting with reloader
127.0.0.1 - - [16/Sep/2015 16:29:42] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/usr/share/pyshared/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/share/pyshared/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/share/pyshared/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/share/pyshared/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/share/pyshared/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/share/pyshared/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/share/pyshared/flask/app.py", line 1473, in full_dispatch_request
    rv = self.preprocess_request()
  File "/usr/share/pyshared/flask/app.py", line 1666, in preprocess_request
    rv = func()
  File "/opt/flasky/app/auth/views.py", line 14, in before_request
    if current_user.is_authenticated() \
TypeError: 'bool' object is not callable

Here is the version of some related package I'm using:

Python 2.7.9
Flask==0.10.1
Flask-Bootstrap==3.3.5.6
Flask-Login==0.3.0
Flask-Mail==0.9.1
Flask-Migrate==1.5.1
Flask-Moment==0.5.1
Flask-SQLAlchemy==2.0
Flask-Script==2.0.5
Flask-WTF==0.12
Jinja2==2.7.3
WTForms==2.0.2
Werkzeug==0.9.6

Thank you so much if you can help me solve this problem.

@jerrypy
Copy link
Author

jerrypy commented Sep 16, 2015

I've already solved this problem.
Since 0.3.0, Flask-Login has set is_active is_authenticated is_anonymous to property in UserMixin, so we should use current_user.is_authenticated instead of current_user.is_authenticated().

@miguelgrinberg
Copy link
Owner

@jerrypy Wow, that is a pretty awful change that is going to break every application. Thanks for doing the research. Not sure how I'll handle this, need to think about it.

@ghost
Copy link

ghost commented Sep 17, 2015

@jerrypy Thanks, I also met this problem some days ago.

@florianperrenet
Copy link

also had this problem, thanks @jerrypy for solving this!

@miguelgrinberg
Copy link
Owner

The repo has been updated to work with Flask-Login 0.3.0. I've added an errata entry for this problem on the flaskbook.com site.

@fireflystar
Copy link

hello @miguelgrinberg ,i git clone flasky project on github,i met this problem today。
do we have a new version of flasky ? how could we get it?

@goshlanguage
Copy link

@jerrypy Thank you!!!

@volosovich
Copy link

@jerrypy Thank you very much!!!

@JJVvV
Copy link

JJVvV commented Nov 4, 2015

@jerrypy Thanks very much ! It botherd me several hours.

@ResidentMario
Copy link

The docs are wrong! If possible please update the documentation (at https://flask-login.readthedocs.org/en/latest/#your-user-class) to document this change, I had to employ Google-fu to solve this issue.

@miguelgrinberg
Copy link
Owner

@ResidentMario I agree with you. In my opinion this change causes more trouble than its worth, and if it was up to me I would have never made it. Unfortunately the maintainer of Flask-Login has different views, he seems to not be too concerned about backwards compatibility.

I have updated the Flasky repository, and also added the changes to the book errata. Whenever O'Reilly reprints the book, the correct code will be used. I know it isn't much, but unfortunately I cannot do more from my side.

Hopefully Google will send people having the problem to this page, where the situation is explained.

@macfire
Copy link

macfire commented Nov 11, 2015

@jerrypy Thank you.

@ajohnclark
Copy link

Face palm. Thanks Jerrypy/everyone.

@popadotstudio
Copy link

This is a silly change, from getter function to property -- broke site instantly for no good reason.

@miguelgrinberg
Copy link
Owner

@veryxcit I'm with you 100%. Really sorry (and not happy at all) that Flask-Login rolled out this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests