From c7fa36efbad4accfdcdd935e4e8359e97cf88d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Thu, 26 Oct 2017 21:36:09 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20#14=20:=20V=C3=A9rifie=20ipType=20correct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/models.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/machines/models.py b/machines/models.py index 102289d5..020b7f0d 100644 --- a/machines/models.py +++ b/machines/models.py @@ -460,6 +460,15 @@ class Interface(models.Model): def clean(self, *args, **kwargs): """ Formate l'addresse mac en mac_bare (fonction filter_mac) et assigne une ipv4 dans le bon range si inexistante ou incohérente""" + # If type was an invalid value, django won't create an attribute type + # but try clean() as we may be able to create it from another value + # so even if the error as yet been detected at this point, django + # continues because the error might not prevent us from creating the + # instance. + # But in our case, it's impossible to create a type value so we raise + # the error. + if not hasattr(self, 'type') : + raise ValidationError("Le type d'ip choisi n'est pas valide") self.filter_macaddress() self.mac_address = str(EUI(self.mac_address)) or None if not self.ipv4 or self.type.ip_type != self.ipv4.ip_type: