Browse Source

Fix signal handling for subnets in case no configuration is associated to the subnet

Baptiste Jonglez 10 years ago
parent
commit
7d59ca1447
1 changed files with 10 additions and 4 deletions
  1. 10 4
      coin/configuration/models.py

+ 10 - 4
coin/configuration/models.py

@@ -3,6 +3,7 @@ from django.db import models
 from polymorphic import PolymorphicModel
 from coin.offers.models import OfferSubscription
 from django.db.models.signals import post_save, post_delete
+from django.core.exceptions import ObjectDoesNotExist
 from django.dispatch import receiver
 
 from coin.resources.models import IPSubnet
@@ -80,9 +81,12 @@ def subnet_save_event(sender, **kwargs):
     Django signals.
     """
     subnet = kwargs['instance']
-    config = subnet.configuration
-    if config:
+    try:
+        config = subnet.configuration
         config.save_subnet(subnet, kwargs['created'])
+    except ObjectDoesNotExist:
+        pass
+
 
 @receiver(post_delete, sender=IPSubnet)
 def subnet_delete_event(sender, **kwargs):
@@ -90,6 +94,8 @@ def subnet_delete_event(sender, **kwargs):
     do whatever it needs to do with it.
     """
     subnet = kwargs['instance']
-    config = subnet.configuration
-    if config:
+    try:
+        config = subnet.configuration
         config.delete_subnet(subnet)
+    except ObjectDoesNotExist:
+        pass