From 604924231a4c0735c76f8e84557637a9ddbd5444 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 16 Jan 2020 14:47:55 -0500 Subject: [PATCH 1/2] Post-release version bump --- netbox/netbox/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index effff8d8d..479a9a4a2 100644 --- a/netbox/netbox/settings.py +++ b/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() From 5369aef97103aea982f08bce356d869fb22184ae Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 16 Jan 2020 21:39:46 -0500 Subject: [PATCH 2/2] Fixes #3944: Fix AttributeError exception when viewing prefixes list --- docs/release-notes/version-2.7.md | 8 ++++++++ netbox/ipam/fields.py | 10 ++++------ netbox/ipam/lookups.py | 4 ++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index 4876476c9..0e58a466d 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -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)). diff --git a/netbox/ipam/fields.py b/netbox/ipam/fields.py index 845820432..72600d1b9 100644 --- a/netbox/ipam/fields.py +++ b/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) diff --git a/netbox/ipam/lookups.py b/netbox/ipam/lookups.py index 457cd7734..62b356c5d 100644 --- a/netbox/ipam/lookups.py +++ b/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)