Try a more magical way of doing nested transactions

This commit is contained in:
Ben Thorner
2021-04-13 09:10:59 +01:00
parent 6704be4021
commit db81c9c355
10 changed files with 32 additions and 55 deletions

View File

@@ -2,7 +2,8 @@
from flask import Blueprint, abort, current_app, jsonify, request
from sqlalchemy.exc import IntegrityError, SQLAlchemyError
from app import db
from app.dao.dao_utils import nested_transaction
from app.config import QueueNames
from app.dao.annual_billing_dao import set_default_free_allowance_for_service
from app.dao.fact_billing_dao import fetch_usage_year_for_organisation
@@ -120,13 +121,9 @@ def link_service_to_organisation(organisation_id):
service = dao_fetch_service_by_id(data['service_id'])
service.organisation = None
try:
with nested_transaction():
dao_add_service_to_organisation(service, organisation_id)
set_default_free_allowance_for_service(service, year_start=None)
db.session.commit()
except SQLAlchemyError as e:
db.session.rollback()
raise e
return '', 204