I have been a software develper for around 20 years. I am looking forward to work with Python. My other blogs:
https://behainguyen.wordpress.com/
https://behai-nguyen.github.io/
Location
Melbourne, Australia
Education
Master of Applied Science in Computer Science, RMIT, Victoria, Australia
I have been a software develper for around 20 years. I am looking forward to work with Python. My other blogs:
https://behainguyen.wordpress.com/
https://behai-nguyen.github.io/
Location
Melbourne, Australia
Education
Master of Applied Science in Computer Science, RMIT, Victoria, Australia
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.
Hi Behai, there were some changes from 0.6 to 0.8 but they 'should' have been improvements. From the errors I'm seeing it looks as if you are trying to subclass/override the interface and/or create tables or access the db attribute (which is internal and now renamed). There should ideally no longer be any need to do anything other than use the default interface, could you you confirm you are trying 0.8.0 without any such modifications or show me the specific lines the error occurs? Thanks!
I have been a software develper for around 20 years. I am looking forward to work with Python. My other blogs:
https://behainguyen.wordpress.com/
https://behai-nguyen.github.io/
Location
Melbourne, Australia
Education
Master of Applied Science in Computer Science, RMIT, Victoria, Australia
Thank you for replying so quickly. What I did was verifying that "my errors" still occur using 0.4.0. And they do. Then I uninstalled 0.4.0, install 0.6.0, no errors occur for the tests or the application. Then I uninstalled 0.6.0, installed 0.8.0, then I got the three errors as reported in my previous reply, I ran it more than once, the errors were consistent. I then uninstalled 0.8.0, reinstalled 0.6.0 again. No errors, I ran everything more than once.
-- I tested both 0.6.0 and 0.8.0 with exactly the same code.
I have not looked into why the errors occur yet. I will do so in the next few days.
I have been a software develper for around 20 years. I am looking forward to work with Python. My other blogs:
https://behainguyen.wordpress.com/
https://behai-nguyen.github.io/
Location
Melbourne, Australia
Education
Master of Applied Science in Computer Science, RMIT, Victoria, Australia
My E:\book-keeping\setup.py, please note Flask-Session=0.8.0:
"""
Installation script for book_keeping project.
Editable install command:
venv\Scripts\pip.exe install -e .
"""frompathlibimportPathfromsetuptoolsimportsetup,find_packagessetup(name='book-keeping',description='Omphalos Book Keeping.',version='1.0.0',author='Van Be Hai Nguyen',author_email='behai_nguyen@hotmail.com',packages=find_packages(where="src"),package_dir={"":"src"},python_requires='>=3.10',install_requires=['Werkzeug==2.3.4','Flask==2.2.5','python-dotenv==1.0.0','mysql-connector-python==8.0.33','Flask-Login==0.6.2','Flask-SQLAlchemy==3.0.2','Flask-Session=0.8.0','Flask-Bcrypt==1.0.1','Flask-WTF==1.1.1','PyYAML==6.0','simplejson==3.19.1','email-validator==2.0.0','xhtml2pdf==0.2.11','blinker==1.6.2','pytest==7.3.1','coverage==7.2.5',],)
Full application error using version 0.8.0, "application" being venv\Scripts\flask.exe run:
(venv) E:\book-keeping>venv\Scripts\flask.exe run
Traceback (most recent call last):
File "C:\PF\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\PF\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "E:\book-keeping\venv\Scripts\flask.exe\__main__.py", line 7, in <module>
File "E:\book-keeping\venv\lib\site-packages\flask\cli.py", line 1050, in main
cli.main()
File "E:\book-keeping\venv\lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
File "E:\book-keeping\venv\lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "E:\book-keeping\venv\lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "E:\book-keeping\venv\lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "E:\book-keeping\venv\lib\site-packages\click\decorators.py", line 92, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "E:\book-keeping\venv\lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "E:\book-keeping\venv\lib\site-packages\flask\cli.py", line 911, in run_command
raise e from None
File "E:\book-keeping\venv\lib\site-packages\flask\cli.py", line 897, in run_command
app = info.load_app()
File "E:\book-keeping\venv\lib\site-packages\flask\cli.py", line 308, in load_app
app = locate_app(import_name, name)
File "E:\book-keeping\venv\lib\site-packages\flask\cli.py", line 218, in locate_app
__import__(module_name)
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'
I can confirm that, after extracting the above error for this post, I went back to version 0.6.0, and everything works.
-- Please note that, to go back to version 0.6.0, I have to change the entry in setup.py to 'Flask-Session=0.6.0',, then manually install it with:
I have been a software develper for around 20 years. I am looking forward to work with Python. My other blogs:
https://behainguyen.wordpress.com/
https://behai-nguyen.github.io/
Location
Melbourne, Australia
Education
Master of Applied Science in Computer Science, RMIT, Victoria, Australia
-- That is attribute client replaced attribute db. The application runs.
However, my test still results in error:
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.
I have been a software develper for around 20 years. I am looking forward to work with Python. My other blogs:
https://behainguyen.wordpress.com/
https://behai-nguyen.github.io/
Location
Melbourne, Australia
Education
Master of Applied Science in Computer Science, RMIT, Victoria, Australia
Ok I may decide to add again the "keep_existing": True, however this shouldn't be needed. If you delete or comment the following lines and use 0.8.0, I would be interested to know the result. There should be no need to manually create the table as flask-session does this now.
# try:
# from book_keeping.library.fixed_session import FixedSession as Session
# except ImportError:
# print( 'from flask_session import Session' )
from flask_session import Session
I have been a software develper for around 20 years. I am looking forward to work with Python. My other blogs:
https://behainguyen.wordpress.com/
https://behai-nguyen.github.io/
Location
Melbourne, Australia
Education
Master of Applied Science in Computer Science, RMIT, Victoria, Australia
Tests raise the old exception (0.4.0). But the sessions table gets created.
venv\Scripts\flask.exe run no longer raises the old exception (0.4.0) and the table sessions table also gets created.
Please note that, I posted this article on the 24th, November 2022. And labelled the code for this article. That is why I am able to get the code test this problem. I forgot to label database version!
Since the this article, I added more functionalities including database changes till around May 2023, I have since stopped working on this project.
For these tests, for the application (that is, venv\Scripts\flask.exe run), I can only get to the login page. But that should be enough.
Please let me know if you want me to do anything else.
I have been a software develper for around 20 years. I am looking forward to work with Python. My other blogs:
https://behainguyen.wordpress.com/
https://behai-nguyen.github.io/
Location
Melbourne, Australia
Education
Master of Applied Science in Computer Science, RMIT, Victoria, Australia
I do apologise for all the fault alarms. I appreciate your helps.
Thank you and best regards,
...behai.
P.S.
Just a side note, my application has a view session functionality for admins, whereby it just displays existing sessions as JSON. I was using pickle to serialise the session data. Flask-Session 0.8.0 now uses msgspec, the serialisation of sessions.data is now:
Hi there is a recent fix for this in 0.6.0. Please let me know if that works for you
Hi Lex,
I am sorry for my late reply. Thank you very much. I will have a look at it. I have been working on some other things.
Thank you and best regards,
...behai.
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:
This is the new one, which did not happen on version version 0.4.0:
The Application
This is the new one, which did not happen on version version 0.4.0:
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.
Hi Behai, there were some changes from 0.6 to 0.8 but they 'should' have been improvements. From the errors I'm seeing it looks as if you are trying to subclass/override the interface and/or create tables or access the db attribute (which is internal and now renamed). There should ideally no longer be any need to do anything other than use the default interface, could you you confirm you are trying 0.8.0 without any such modifications or show me the specific lines the error occurs? Thanks!
Hi @lxstr,
Thank you for replying so quickly. What I did was verifying that "my errors" still occur using 0.4.0. And they do. Then I uninstalled 0.4.0, install 0.6.0, no errors occur for the tests or the application. Then I uninstalled 0.6.0, installed 0.8.0, then I got the three errors as reported in my previous reply, I ran it more than once, the errors were consistent. I then uninstalled 0.8.0, reinstalled 0.6.0 again. No errors, I ran everything more than once.
-- I tested both 0.6.0 and 0.8.0 with exactly the same code.
I have not looked into why the errors occur yet. I will do so in the next few days.
Thank you and best regards, Lex.
...behai.
Hi Lex,
My
E:\book-keeping\setup.py
, please noteFlask-Session=0.8.0
:My
E:\book-keeping\src\book_keeping\__init__.py
:Please note:
E:\book-keeping\src\book_keeping\library\
DOES NOT havefixed_session.py
module. I renamed it. Please see attached screenshot:My
E:\book-keeping\.env
:Full application error using version 0.8.0, "application" being
venv\Scripts\flask.exe run
:I can confirm that, after extracting the above error for this post, I went back to version 0.6.0, and everything works.
-- Please note that, to go back to version 0.6.0, I have to change the entry in
setup.py
to'Flask-Session=0.6.0',
, then manually install it with:Thank you and best regards,
...behai.
Hi Lex,
Just a little bit more info...
Regarding version 0.8.0, in
E:\book-keeping\src\book_keeping\__init__.py
, change to:from:
-- That is attribute
client
replaced attributedb
. The application runs.However, my test still results in error:
as per version .0.4.0.
Thank you and best regards,
...behai.
Hi Lex,
For version 0.8.0, in
sqlalchemy\sqlalchemy.py
, I copy the following from 0.6.0:to replace:
That is:
And errors disappear. The tests and the application work.
Thank you and best regards,
...behai.
Ok I may decide to add again the "keep_existing": True, however this shouldn't be needed. If you delete or comment the following lines and use 0.8.0, I would be interested to know the result. There should be no need to manually create the table as flask-session does this now.
and
with app.app_context():
Hi Lex,
Based on your advice:
E:\book-keeping\src\book_keeping\__init__.py
modified to:I have also decided to use latest of everything,
E:\book-keeping\setup.py
updated to:I am using the original
Flask-Session 0.8.0
:Test 1: table
sessions
exists:The application runs. That is,
venv\Scripts\flask.exe run
does not raise exception.Tests no longer raise the table
sessions
exists exception. They now raise another unrelated exception.Test 2: I manually removed the existing
sessions
table:The results are as in Test 1. BUT THE TABLE
sessions
DOES NOT GET CREATED.Further note:
With:
Tests raise the old exception (0.4.0). But the
sessions
table gets created.venv\Scripts\flask.exe run
no longer raises the old exception (0.4.0) and the tablesessions
table also gets created.Please note that, I posted this article on the 24th, November 2022. And labelled the code for this article. That is why I am able to get the code test this problem. I forgot to label database version!
Since the this article, I added more functionalities including database changes till around May 2023, I have since stopped working on this project.
For these tests, for the application (that is,
venv\Scripts\flask.exe run
), I can only get to the login page. But that should be enough.Please let me know if you want me to do anything else.
Thank you and best regards,
...behai.
Hi @lxstr,
Your advice works.
And this report from my last response is not correct:
There was something in my code what caused it not to work. I am using all latest packages now.
There is no need for:
I do apologise for all the fault alarms. I appreciate your helps.
Thank you and best regards,
...behai.
P.S.
Just a side note, my application has a view session functionality for admins, whereby it just displays existing sessions as JSON. I was using
pickle
to serialise the session data.Flask-Session 0.8.0
now usesmsgspec
, the serialisation ofsessions.data
is now: