When begin_nested
is used as a context manager, e.g.
with db.session.begin_nested:
# do something
If an IntegrityError
is thrown, will db.session.rollbank()
be called automatically? On the contrary, if no exception is thrown, will db.session.commit()
be automatically called?
If a transaction, such as one from begin_nested
, is used as a context manager, the transaction is commited at exit, or rolled back if there was an error in the block or during commit.
Here is the relevant source: https://github.com/zzzeek/sqlalchemy/blob/81518ae2e2bc622f8cd47287a575ad4c0e43ead1/lib/sqlalchemy/orm/session.py#L558-L569
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