You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sqlalchemy
I am trying to test an endpoint in flask and I need to "refresh" the DB after some commits.
The idea I had was something like :
db=SQLAlchemy()
db.session.begin_nested()
db.session.add(Obj) db.session.commit()
# some code where last commit is important
db.session.add(Obj2) db.session.commit()
# some other code where last commit is important
db.session.rollback()
But it doesn't work unless I have a single commit.
Can you help me please :)
Simon King
unread,
Jun 21, 2021, 5:24:22 AM6/21/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sqlal...@googlegroups.com
Which version of SQLAlchemy are you using, and how are you creating
your engine? I believe savepoints are handled differently in SA 1.4 if
you are using the "future-style" engine.
"""
Calling the Session.commit() or Connection.commit() methods will
always commit the outermost transaction; this is a SQLAlchemy 2.0
specific behavior that is reversed from the 1.x series.
"""
"""
The “subtransaction” pattern that was often used with autocommit mode
is also deprecated in 1.4. This pattern allowed the use of the
Session.begin() method when a transaction were already begun,
resulting in a construct called a “subtransaction”, which was
essentially a block that would prevent the Session.commit() method
from actually committing.
"""