mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Fixes #3944: Fix AttributeError exception when viewing prefixes list
This commit is contained in:
parent
604924231a
commit
5369aef971
@ -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)
|
# v2.7.0 (2020-01-16)
|
||||||
|
|
||||||
**Note:** This release completely removes the topology map feature ([#2745](https://github.com/netbox-community/netbox/issues/2745)).
|
**Note:** This release completely removes the topology map feature ([#2745](https://github.com/netbox-community/netbox/issues/2745)).
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from netaddr import AddrFormatError, IPNetwork, IPAddress
|
from netaddr import AddrFormatError, IPNetwork
|
||||||
|
|
||||||
from . import lookups
|
from . import lookups
|
||||||
from .formfields import IPFormField
|
from .formfields import IPFormField
|
||||||
@ -23,11 +23,9 @@ class BaseIPField(models.Field):
|
|||||||
if not value:
|
if not value:
|
||||||
return value
|
return value
|
||||||
try:
|
try:
|
||||||
if '/' in str(value):
|
# Always return a netaddr.IPNetwork object. (netaddr.IPAddress does not provide a mask.)
|
||||||
return IPNetwork(value)
|
return IPNetwork(value)
|
||||||
else:
|
except AddrFormatError:
|
||||||
return IPAddress(value)
|
|
||||||
except AddrFormatError as e:
|
|
||||||
raise ValidationError("Invalid IP address format: {}".format(value))
|
raise ValidationError("Invalid IP address format: {}".format(value))
|
||||||
except (TypeError, ValueError) as e:
|
except (TypeError, ValueError) as e:
|
||||||
raise ValidationError(e)
|
raise ValidationError(e)
|
||||||
|
@ -103,6 +103,10 @@ class NetHost(Lookup):
|
|||||||
class NetIn(Lookup):
|
class NetIn(Lookup):
|
||||||
lookup_name = 'net_in'
|
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):
|
def as_sql(self, qn, connection):
|
||||||
lhs, lhs_params = self.process_lhs(qn, connection)
|
lhs, lhs_params = self.process_lhs(qn, connection)
|
||||||
rhs, rhs_params = self.process_rhs(qn, connection)
|
rhs, rhs_params = self.process_rhs(qn, connection)
|
||||||
|
Loading…
Reference in New Issue
Block a user