A database transaction is a temporary workspace for database changes. Write operations such as INSERT, UPDATE, and DELETE remain invisible to other users until the application commits them. Committing confirms the changes and makes them permanent; rolling back discards temporary changes. section 8.2.5
A practical database layer commits only successful write queries. It catches execution errors, rolls back the affected transaction, and re-raises the exception so the application can handle or display the failure instead of retaining partial changes. section 8.2.5
Commit successful writes and undo failures
A SQLAlchemy session executes a parameterized query inside a try block. When write is true, session.commit() saves the changes. If execution raises an exception, session.rollback() restores the database before the exception is re-raised.













