I'm writing the sign up/sign in system for a ecommerce site, and using flask-security (http://pythonhosted.org/Flask-Security/) to handle the signup feature. Part of the basic setup requires the following signup.py module:
from flask.ext.security import SQLAlchemyUserDatastore, Security
from app.models import User, Role
from app import app, db
# Setup Flask Security
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
security = Security(app, user_datastore)
I then have to import the user_datastore and security objects into my views.py module as follows:
from app.signup import user_datastore, security
The thing is, as soon as I include the above import statement into my views module, my whole app crashes, and I get the following traceback error when I try to run my unit or behavior tests (edited for readability)
======================================================================
ERROR: Failure: AttributeError ('_FakeSignal' object has no attribute 'connect_via')
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose/loader.py", line 413, in loadTestsFromName
addr.filename, addr.module)
File "/Library/Python/2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Library/Python/2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/tests/test_database.py", line 6, in <module>
from app import app, db, models
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/app/__init__.py", line 9, in <module>
from app import views, models
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/app/views.py", line 7, in <module>
from app.signup import user_datastore
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/app/signup.py", line 7, in <module>
security = Security(app, user_datastore)
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/flask/lib/python2.7/site-packages/flask_security/core.py", line 346, in __init__
self._state = self.init_app(app, datastore, **kwargs)
File "/Users/faiyamrahman/programming/Python/WebApps/NibsNWhiskeyFull/flask/lib/python2.7/site-packages/flask_security/core.py", line 368, in init_app
identity_loaded.connect_via(app)(_on_identity_loaded)
AttributeError: '_FakeSignal' object has no attribute 'connect_via'
I have no idea what this means. I've tried reading the flask-security documentation, but I don't understand why it's happening. Thanks to anyone who takes a stab at this!
Short Answer: You are missing blinker library. EDIT: You confirmed that your virtual environment could not find blinker and you re-installed it.
Long Answer:
I think the error is coming from Flask Signals. Look at this code from signals:
So I think that the code tries to find the
blinker
library and in your case, it is not able to import it and hence it tries to use the_FakeSignal
class.The
_FakeSignal
class does not have aconnect_via
attribute defined as you can see belowThe
connect_via
attribute that Flask-Security is trying to load is actually provided by theblinker
library and since no blinker, no connect_via. Hence it fails.So you should install blinker first. However, I think that Flask-Security code should also check for
blinker
before trying to useconnect_via
.