Open utterances-bot opened 6 months ago
Hi @lxstr,
First, thank you for your hard works. And do apologise for the late reply. I had been caught up in something else.
I have today just finished testing out Flask-Session new versions.
Following are what I have found out:
Version 0.6.0 works as you have stated. I have been able to run tests multiple without the stated error occured.
Version 0.8.0 is worse than version 0.4.0, it actually raises 3 ( three ) errors:
On Tests
This is the one that occurs using version 0.4.0:
E sqlalchemy.exc.InvalidRequestError: Table 'sessions' is already defined for this MetaData instance. Specify 'extend_existing=True' to redefine options and columns on an existing Table object.
This is the new one, which did not happen on version version 0.4.0:
ERROR tests/bro/test_rbac_bro.py::test_list_all_system_menu - AttributeError: 'SqlAlchemySessionInterface' object has no attribute 'db'
ERROR tests/unit/test_rbac_system_menu.py::test_sqlalchemy_filter_id_equal_01 - sqlalchemy.exc.InvalidRequestError: Table 'sessions' is already defined for this MetaData instance. Specify 'exten...
ERROR tests/unit/test_rbac_system_menu.py::test_sqlalchemy_filter_id_equal_02 - sqlalchemy.exc.InvalidRequestError: Table 'sessions' is already defined for this MetaData instance. Specify 'exten...
The Application
This is the new one, which did not happen on version version 0.4.0:
...
File "E:\book-keeping\app.py", line 16, in <module>
app = create_app()
File "e:\book-keeping\src\book_keeping\__init__.py", line 45, in create_app
init_app_session( app )
File "e:\book-keeping\src\book_keeping\__init__.py", line 69, in init_app_session
app_session.app.session_interface.db.create_all()
AttributeError: 'SqlAlchemySessionInterface' object has no attribute 'db'
Please note, I did also verify that version 0.4.0 causes error as has been described in post.
Thank you and best regards,
...behai.
Python: a workaround for SQLAlchemy “Table ‘sessions’ is already defined” exception during tests. | behai-nguyen software development learnings and documentation
During tests, Flask-Session intermittently causes the exception “sqlalchemy.exc.InvalidRequestError: Table ‘sessions’ is already defined for this MetaData instance. Specify ‘extend_existing=True’ to redefine options and columns on an existing Table object.” I’m presenting a workaround in this post.
https://behai-nguyen.github.io/2022/11/24/flask-session-sessions-exists-exception.html