~maas-committers/maas/1.6

« back to all changes in this revision

Viewing changes to src/maasserver/migrations/0088_z_backport_trunk_0099.py

  • Committer: MaaS Lander
  • Author(s): Julian Edwards
  • Date: 2014-08-25 01:56:22 UTC
  • mfrom: (2550.1.1 1.6-savepoints-migration)
  • Revision ID: maas_lander-20140825015622-hh5g37qrap3tmr1x
[r=julian-edwards][bug=1360008][author=julian-edwards] Fix the 0088_z_backport_trunk_0099 migration which gave a transaction error if matching Network records already existed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from django.core.exceptions import ValidationError
2
 
from django.db import models
 
2
from django.db import models, transaction
3
3
from django.db.utils import IntegrityError
4
4
from netaddr import IPNetwork
5
5
from south.db import db
44
44
                    "Auto created when creating interface %s on cluster "
45
45
                    "%s" % (interface.interface, interface.nodegroup.name)),
46
46
                )
 
47
            sid = transaction.savepoint()
47
48
            try:
48
49
                network.save()
 
50
                transaction.savepoint_commit(sid)
49
51
            except (ValidationError, IntegrityError):
50
52
                # It probably already exists, keep calm and carry on.
 
53
                transaction.savepoint_rollback(sid)
51
54
                continue
52
55
 
53
56
    def backwards(self, orm):