Просмотр исходного кода

Merge branch 'develop' into 3941-ip-assign-exception

Jeremy Stretch 6 лет назад
Родитель
Сommit
1c0e0fec4c
4 измененных файлов с 10 добавлено и 7 удалено
  1. 1 0
      docs/release-notes/version-2.7.md
  2. 4 6
      netbox/ipam/fields.py
  3. 4 0
      netbox/ipam/lookups.py
  4. 1 1
      netbox/netbox/settings.py

+ 1 - 0
docs/release-notes/version-2.7.md

@@ -3,6 +3,7 @@
 ## Bug Fixes
 
 * [#3941](https://github.com/netbox-community/netbox/issues/3941) - Fixed exception when attempting to assign IP to interface
+* [#3944](https://github.com/netbox-community/netbox/issues/3944) - Fix AttributeError exception when viewing prefixes list
 
 ---
 

+ 4 - 6
netbox/ipam/fields.py

@@ -1,6 +1,6 @@
 from django.core.exceptions import ValidationError
 from django.db import models
-from netaddr import AddrFormatError, IPNetwork, IPAddress
+from netaddr import AddrFormatError, IPNetwork
 
 from . import lookups
 from .formfields import IPFormField
@@ -23,11 +23,9 @@ class BaseIPField(models.Field):
         if not value:
             return value
         try:
-            if '/' in str(value):
-                return IPNetwork(value)
-            else:
-                return IPAddress(value)
-        except AddrFormatError as e:
+            # Always return a netaddr.IPNetwork object. (netaddr.IPAddress does not provide a mask.)
+            return IPNetwork(value)
+        except AddrFormatError:
             raise ValidationError("Invalid IP address format: {}".format(value))
         except (TypeError, ValueError) as e:
             raise ValidationError(e)

+ 4 - 0
netbox/ipam/lookups.py

@@ -103,6 +103,10 @@ class NetHost(Lookup):
 class NetIn(Lookup):
     lookup_name = 'net_in'
 
+    def get_prep_lookup(self):
+        # Don't cast the query value to a netaddr object, since it may or may not include a mask.
+        return self.rhs
+
     def as_sql(self, qn, connection):
         lhs, lhs_params = self.process_lhs(qn, connection)
         rhs, rhs_params = self.process_rhs(qn, connection)

+ 1 - 1
netbox/netbox/settings.py

@@ -12,7 +12,7 @@ from django.core.exceptions import ImproperlyConfigured
 # Environment setup
 #
 
-VERSION = '2.7.0'
+VERSION = '2.7.1-dev'
 
 # Hostname
 HOSTNAME = platform.node()