Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Session' object has no attribute 'transaction' #331

Open
adorsett opened this issue Apr 27, 2023 · 6 comments
Open

AttributeError: 'Session' object has no attribute 'transaction' #331

adorsett opened this issue Apr 27, 2023 · 6 comments

Comments

@adorsett
Copy link

Getting the same traceback using sqlalchemy-continuum with sqlalchemy and flask-sqlalchemy. I've tried both and I still get this:

flaskapp  | Traceback (most recent call last):
flaskapp  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2528, in wsgi_app
flaskapp  |     response = self.full_dispatch_request()
flaskapp  |   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1815, in full_dispatch_request
flaskapp  |     self.ensure_sync(func)()
flaskapp  |   File "/app/app/__init__.py", line 54, in init_db
flaskapp  |     user_datastore.commit()
flaskapp  |   File "/usr/local/lib/python3.9/site-packages/flask_security/datastore.py", line 66, in commit
flaskapp  |     self.db.session.commit()
flaskapp  |   File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/scoping.py", line 553, in commit
flaskapp  |     return self._proxied.commit()
flaskapp  |   File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1905, in commit
flaskapp  |     trans.commit(_to_root=True)
flaskapp  |   File "<string>", line 2, in commit
flaskapp  |   File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/state_changes.py", line 137, in _go
flaskapp  |     ret_value = fn(self, *arg, **kw)
flaskapp  |   File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1230, in commit
flaskapp  |     self.session.dispatch.after_commit(self.session)
flaskapp  |   File "/usr/local/lib/python3.9/site-packages/sqlalchemy/event/attr.py", line 378, in __call__
flaskapp  |     fn(*args, **kw)
flaskapp  |   File "/usr/local/lib/python3.9/site-packages/sqlalchemy_continuum/manager.py", line 365, in clear
flaskapp  |     if session.transaction.nested:
flaskapp  | AttributeError: 'Session' object has no attribute 'transaction'

I changed line 365 in manager.py to if session.get_transaction().nested: and my traceback went away. Not sure if this is the correct behavior, but for some reason I'm getting an error and that made it go away.

@guzzijones
Copy link

Thanks, I just bumped into this as well. I will take a look further and see why this is happening. I will try to get a PR done.

@marksteward
Copy link
Collaborator

I'm fixing this as part of #326

@guzzijones
Copy link

this appears to happen for me if i use sqlalchemy 2.0

@guzzijones
Copy link

thanks @marksteward

anthraxx added a commit to archlinux/arch-security-tracker that referenced this issue May 14, 2023
@ahmedmorad101
Copy link

in sqlalchemy 2.0 they replace transaction with _transaction

@michaeltoohig
Copy link

So just for others coming to this issue, I did succeed in using SQLAlchemy 2.0 with continuum. I had found this error because my version of continuum was old but upgrading continuum & sqlalchemy_utils fixed it.

But for further context, I was upgrading a project of mine which I haven't touched in a few years so I've also migrated from psycopg2 to psycopg3 in the process of fixing this so not sure how relevant that may have been.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants