New strategy for transaction management.

Introduce a contextmanger function to handle exceptions and nested
transactions. Using the nested_transaction will start a
nested transaction with `db.session.begin_nested`, once the nested
transaction is complete the commit will happen.
`@transactional` has been updated to commit unless in a nested
transaction.
This commit is contained in:
Rebecca Law
2021-04-13 15:02:46 +01:00
parent cf35135605
commit 93908bacda
9 changed files with 29 additions and 52 deletions

View File

@@ -1,12 +1,7 @@
from sqlalchemy.sql.expression import func
from app import db
from app.dao.dao_utils import (
VersionOptions,
nested_transactional,
transactional,
version_class,
)
from app.dao.dao_utils import VersionOptions, transactional, version_class
from app.models import Domain, Organisation, Service, User
@@ -110,7 +105,7 @@ def _update_organisation_services(organisation, attribute, only_where_none=True)
db.session.add(service)
@nested_transactional
@transactional
@version_class(Service)
def dao_add_service_to_organisation(service, organisation_id):
organisation = Organisation.query.filter_by(