Skip to content
Snippets Groups Projects
models.py 40.2 KiB
Newer Older
        attempts = 0
        while (not success and attempts < 5):
            attempts = attempts + 1
            if not self.N:
                if self.event.voevent_set.count():
                    self.N = int(self.event.voevent_set.aggregate(models.Max('N'))['N__max']) + 1
                else:
                    self.N = 1
            try:
                super(VOEvent, self).save(*args, **kwargs)
                success = True
            except IntegrityError:
                # IntegrityError means an attempt to insert a duplicate
                # key or to violate a foreignkey constraint.
                # We are under race conditions.  Let's try again.
                pass

        if not success:
            # XXX Should this be a custom exception?  That way we could catch it
            # in the views that use it and give an informative error message.
            raise Exception("Too many attempts to save log message. Something is wrong.")