'Flask-SQLAlchemy - Delay commit until last

I'm using Flask-SQLAlchemy and I had the idea to perform the db.session.commit() on successful execution of the controller.

Given this, I have two questions:

  1. Can I have a problem during the execution of the controller by delaying the commit until the last moment (for example, that some values remain null, as is the case of the id)?

  2. In case the execution does not finish correctly (for example an unhandled exception arises during the execution), do I have to do a rollback explicitly to discard the changes in case there are or can I just not do nothing and Flask-SQLAlchemy takes care of that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source