mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
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:
@@ -1,7 +1,12 @@
|
||||
from sqlalchemy.sql.expression import 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.models import Domain, Organisation, Service, User
|
||||
|
||||
|
||||
@@ -105,7 +110,7 @@ def _update_organisation_services(organisation, attribute, only_where_none=True)
|
||||
db.session.add(service)
|
||||
|
||||
|
||||
@transactional
|
||||
@nested_transactional
|
||||
@version_class(Service)
|
||||
def dao_add_service_to_organisation(service, organisation_id):
|
||||
organisation = Organisation.query.filter_by(
|
||||
|
||||
Reference in New Issue
Block a user