Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
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.")