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

This commit is contained in:
Jeremy Stretch 2020-01-16 21:42:27 -05:00 committed by GitHub
commit 1c0e0fec4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

View File

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

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)

View File

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