Fixes #3944: Fix AttributeError exception when viewing prefixes list

This commit is contained in:
Jeremy Stretch 2020-01-16 21:39:46 -05:00
parent 604924231a
commit 5369aef971
3 changed files with 16 additions and 6 deletions

View File

@ -1,3 +1,11 @@
# v2.7.1 (FUTURE)
# Bug Fixes
* [#3944](https://github.com/netbox-community/netbox/issues/3944) - Fix AttributeError exception when viewing prefixes list
---
# v2.7.0 (2020-01-16)
**Note:** This release completely removes the topology map feature ([#2745](https://github.com/netbox-community/netbox/issues/2745)).

View File

@ -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)

View File

@ -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)