I'm pretty new in Python and SQLAlchemy, so basically I changed from:
session = Session()
session.query(SOMETHING_HERE).filter()
to
session = Session()
nested_session = session.begin_nested()
nested_session.query(SOMETHING_HERE).filter()
in order to use SAVEPOINTS. But I'm getting the error:
AttributeError: 'SessionTransaction' object has no attribute 'query'
I did a deep dive in the documentation, like these:
https://docs.sqlalchemy.org/en/13/orm/session_api.html#sqlalchemy.orm.session.SessionTransaction
https://docs.sqlalchemy.org/en/13/orm/session_transaction.html
But it did not help me.
Questions: Am I able to use begin_nested to run query with filter like that or I need to change the approach? Is this a version issue (sql alchemy for example)?
This was originally posted as a comment.
You don't need to reassign the result of session.begin_nested() to anything, you can just do: session.begin_nested() and then proceed with session.query(SOMETHING_HERE).filter()
Reference for this assertion: https://docs.sqlalchemy.org/en/13/orm/session_transaction.html#using-savepoint
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With