Commit 357c3f0d authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

quotaholder: Do no side effect on failed commissions

Make sure that no Commission or Provision entry is created when
issue_commission fails, even if the transaction is committed.
parent 76db355c
......@@ -148,11 +148,9 @@ class QuotaholderDjangoDBCallpoint(object):
if name is None:
name = ""
create = Commission.objects.create
commission = create(clientkey=clientkey, name=name)
serial = commission.serial
operations = Operations()
provisions_to_create = []
provisions = self._provisions_to_list(provisions)
keys = [key for (key, value) in provisions]
......@@ -187,17 +185,21 @@ class QuotaholderDjangoDBCallpoint(object):
operations.prepare(Release, th, abs_quantity, force)
holdings[key] = th
Provision.objects.create(serial=commission,
holder=th.holder,
source=th.source,
resource=th.resource,
quantity=quantity)
provisions_to_create.append((key, quantity))
except QuotaholderError:
operations.revert()
raise
return serial
commission = Commission.objects.create(clientkey=clientkey, name=name)
for (holder, source, resource), quantity in provisions_to_create:
Provision.objects.create(serial=commission,
holder=holder,
source=source,
resource=resource,
quantity=quantity)
return commission.serial
def _log_provision(self,
commission, provision, holding, log_time, reason):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment