Does begin_nested() automatically rollback/commit?


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.rollback () be called automatically? On the contrary, if no exception is thrown, will db.session.commit() be automatically called?

Asked By: Kar



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:

Answered By: davidism
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.