Adding @nested_transactional for transactions that require more than one

db update/insert.

Using a savepoint for the multiple transactions allows us to rollback if
there is an error when executing the second db transaction.
However, this does add a bit of complexity. Developers need to manage
the db session when calling multiple nested tranactions.

Unit tests have been added to test this functionality and some end to
end tests have been done to make sure all transactions are rollback if
there is an exception while executing the transaction.
This commit is contained in:
Rebecca Law
2021-04-12 13:52:40 +01:00
parent 7806bb5246
commit 6704be4021
10 changed files with 103 additions and 38 deletions

View File

@@ -7,7 +7,12 @@ from sqlalchemy.orm import joinedload
from sqlalchemy.sql.expression import and_, asc, case, func
from app import db
from app.dao.dao_utils import VersionOptions, transactional, version_class
from app.dao.dao_utils import (
VersionOptions,
nested_transactional,
transactional,
version_class,
)
from app.dao.date_util import get_current_financial_year
from app.dao.email_branding_dao import dao_get_email_branding_by_name
from app.dao.letter_branding_dao import dao_get_letter_branding_by_name
@@ -284,7 +289,7 @@ def dao_fetch_service_by_id_and_user(service_id, user_id):
).one()
@transactional
@nested_transactional
@version_class(Service)
def dao_create_service(
service,