If an error occurs during a sql transaction, there is no rollback and the database can be locked.
We should use context manager to better handling sql session: commit on success and rollback on error.
Possible implementation: https://stackoverflow.com/a/29805305/7497291