Issue
I'm learning authentication functionality with Flask-SQLAlchemy
, so building out very basic apps where a user (attributes: name, email and password) is able to sign-up and login, get redirected to a dummy profile page, and that's it. The puzzling behaviour is the tutorials I've done won't work all the way through if I use a virtual environment.
To show this behaviour, follow this digital ocean tutorial. At step 6, we have:
>>> from project import db, create_app
>>> db.create_all(app=create_app())
If I have the auth
environment active (as the tutorial states I should), I get the following error message:
/.../flask_auth_app/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py:833: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
warnings.warn(FSADeprecationWarning(
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../flask_auth_app/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 1039, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/.../flask_auth_app/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 1031, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/.../flask_auth_app/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 962, in get_engine
return connector.get_engine()
File "/.../flask_auth_app/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 555, in get_engine
options = self.get_options(sa_url, echo)
File "/.../flask_auth_app/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 570, in get_options
self._sa.apply_driver_hacks(self._app, sa_url, options)
File "/.../flask_auth_app/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 914, in apply_driver_hacks
sa_url.database = os.path.join(app.root_path, sa_url.database)
AttributeError: can't set attribute
I'll get the same error if I try to sign up a new user while running the app on localhost
- that is, I can only successfully sign up a new user if I don't have a virtual environment running, so that the app reads from global versions of installed packages instead.
This error goes away if I deactivate the environment before running python3
. I'll get the same behaviour if I follow this tutorial, example code given here.
Package Versions
This is the same in venv
and ~/miniconda3/lib/python3.8/site-packages
. I'm on a MacOS Big Sur v11.2.3.
Flask==1.1.2
Flask-Login==0.5.0
Flask-SQLAlchemy==2.4.4
SQLAlchemy==1.4.0
Solution
I recently delt with that same error message. It is actually due to an upgrade in SQLAlchemy, which gets installed as a dependency of flask-sqlalchemy.
You can find the question I posted on stackoverflow for the issue here:
The problem gets solved by uninstalling SQLAlchemy==1.4.0 and installing the previous version SQLAlchemy==1.3.23.
Try doing that in your virtual environ and see if it helps.
Answered By - Ange Uwase
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.