AttributeError: module 'sqlalchemy' has no attribute '__all__'
Question:
In my GitHub CI I get errors like the one below since today:
File "/home/runner/.local/lib/python3.8/site-packages/fb4/login_bp.py", line 12, in <module>
from fb4.sqldb import db
File "/home/runner/.local/lib/python3.8/site-packages/fb4/sqldb.py", line 8, in <module>
db = SQLAlchemy()
File "/home/runner/.local/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 758, in __init__
_include_sqlalchemy(self, query_class)
File "/home/runner/.local/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 112, in _include_sqlalchemy
for key in module.__all__:
AttributeError: module 'sqlalchemy' has no attribute '__all__'
CRITICAL: Exiting due to uncaught exception <class 'ImportError'>
without being aware of any significant commit that might cause this.
My local tests and my Jenkins CI still work.
I changed the matrix to stick to python 3.8 instead of also trying 3.9, 3.10 and 3.11 also taking into account that a similar problem in python 3.9 AttributeError: module 'posix' has no attribute '__all__' was due to missing 3.9 support.
How can the above error could be debugged and mitigated?
My assumption is that the problem is in the setup/environment or some strange behaviour change of GitHub actions, Python, pip or the test environment or whatever.
I am a committer of the projects involved which are:
- https://github.com/WolfgangFahl/pyOnlineSpreadSheetEditing
and potentially
- https://github.com/WolfgangFahl/pyFlaskBootstrap4
Update:
After following the suggestions by @snakecharmerb the logs
Now show a version conflict
RROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
The conflict is caused by:
The user requested Flask~=2.0.2
bootstrap-flask 1.8.0 depends on Flask
flask-dropzone 1.6.0 depends on Flask
flask-login 0.6.2 depends on Flask>=1.0.4
flask-httpauth 1.0.0 depends on Flask
flask-sqlalchemy 3.0.2 depends on Flask>=2.2
Which is interesting since i am trying to avoid the ~ notation … and indeed it was a typo … let’s see whether the fix to upgrade Flask-SQLAlchemy>=3.0.2 works now.
I have accepted the answer after setting the version as suggested.
There are followup problems but the question is answered.
Answers:
It seems the .__all__
attribute has been removed in the recently released SQLAlchemy 2.0. You may need to pin the SQLAlchemy version in your config somehow. Or ensure that you are using Flask-SQLAlchemy 3.0.2 or later, as this issue suggests that version has the required fix.
I have solved this problem by adding a specific version of SQLAlchemy to my requirement before flask-SQLAlchemy. Example:
Flask==2.1.3
SQLAlchemy==1.4 (new one)
flask-restx==0.5.1
I noticed that pip was installing the 2.0 version
For me it worked when I upgraded flask-sqlalchemy to 3.0.3 version.
In my GitHub CI I get errors like the one below since today:
File "/home/runner/.local/lib/python3.8/site-packages/fb4/login_bp.py", line 12, in <module>
from fb4.sqldb import db
File "/home/runner/.local/lib/python3.8/site-packages/fb4/sqldb.py", line 8, in <module>
db = SQLAlchemy()
File "/home/runner/.local/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 758, in __init__
_include_sqlalchemy(self, query_class)
File "/home/runner/.local/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 112, in _include_sqlalchemy
for key in module.__all__:
AttributeError: module 'sqlalchemy' has no attribute '__all__'
CRITICAL: Exiting due to uncaught exception <class 'ImportError'>
without being aware of any significant commit that might cause this.
My local tests and my Jenkins CI still work.
I changed the matrix to stick to python 3.8 instead of also trying 3.9, 3.10 and 3.11 also taking into account that a similar problem in python 3.9 AttributeError: module 'posix' has no attribute '__all__' was due to missing 3.9 support.
How can the above error could be debugged and mitigated?
My assumption is that the problem is in the setup/environment or some strange behaviour change of GitHub actions, Python, pip or the test environment or whatever.
I am a committer of the projects involved which are:
- https://github.com/WolfgangFahl/pyOnlineSpreadSheetEditing
and potentially - https://github.com/WolfgangFahl/pyFlaskBootstrap4
Update:
After following the suggestions by @snakecharmerb the logs
Now show a version conflict
RROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
The conflict is caused by:
The user requested Flask~=2.0.2
bootstrap-flask 1.8.0 depends on Flask
flask-dropzone 1.6.0 depends on Flask
flask-login 0.6.2 depends on Flask>=1.0.4
flask-httpauth 1.0.0 depends on Flask
flask-sqlalchemy 3.0.2 depends on Flask>=2.2
Which is interesting since i am trying to avoid the ~ notation … and indeed it was a typo … let’s see whether the fix to upgrade Flask-SQLAlchemy>=3.0.2 works now.
I have accepted the answer after setting the version as suggested.
There are followup problems but the question is answered.
It seems the .__all__
attribute has been removed in the recently released SQLAlchemy 2.0. You may need to pin the SQLAlchemy version in your config somehow. Or ensure that you are using Flask-SQLAlchemy 3.0.2 or later, as this issue suggests that version has the required fix.
I have solved this problem by adding a specific version of SQLAlchemy to my requirement before flask-SQLAlchemy. Example:
Flask==2.1.3
SQLAlchemy==1.4 (new one)
flask-restx==0.5.1
I noticed that pip was installing the 2.0 version
For me it worked when I upgraded flask-sqlalchemy to 3.0.3 version.