From 58227293f38abd144d19579d43e4848c134dfb99 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Date: Fri, 5 Jan 2024 10:30:04 -0800 Subject: [PATCH] 14637 update to Django 5 (#14675) * 14637 update to Django 5 * 14637 fix tests * 14637 remove extra assignment * Syntax tweak --------- Co-authored-by: Jeremy Stretch --- base_requirements.txt | 2 +- netbox/core/tests/test_filtersets.py | 4 +--- netbox/dcim/models/cables.py | 8 ++++++-- netbox/dcim/models/devices.py | 2 +- netbox/extras/models/configs.py | 2 +- requirements.txt | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/base_requirements.txt b/base_requirements.txt index 82c2d1abc..0c7e54b13 100644 --- a/base_requirements.txt +++ b/base_requirements.txt @@ -4,7 +4,7 @@ bleach # The Python web framework on which NetBox is built # https://docs.djangoproject.com/en/stable/releases/ -Django<5.0 +Django<5.1 # Django middleware which permits cross-domain API requests # https://github.com/adamchainz/django-cors-headers/blob/main/CHANGELOG.rst diff --git a/netbox/core/tests/test_filtersets.py b/netbox/core/tests/test_filtersets.py index e6e52a8b3..8ff104142 100644 --- a/netbox/core/tests/test_filtersets.py +++ b/netbox/core/tests/test_filtersets.py @@ -1,8 +1,6 @@ -from datetime import datetime +from datetime import datetime, timezone from django.test import TestCase -from django.utils import timezone - from utilities.testing import ChangeLoggedFilterSetTests from ..choices import * from ..filtersets import * diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index d1c80d0be..7ae755602 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -317,10 +317,14 @@ class CableTermination(ChangeLoggedModel): super().clean() # Check for existing termination - existing_termination = CableTermination.objects.exclude(cable=self.cable).filter( + qs = CableTermination.objects.filter( termination_type=self.termination_type, termination_id=self.termination_id - ).first() + ) + if self.cable.pk: + qs = qs.exclude(cable=self.cable) + + existing_termination = qs.first() if existing_termination is not None: raise ValidationError( f"Duplicate termination found for {self.termination_type.app_label}.{self.termination_type.model} " diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index e61c2feb8..b0edf49fe 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -1098,7 +1098,7 @@ class Device( :param if_master: If True, return VC member interfaces only if this Device is the VC master. """ - filter = Q(device=self) + filter = Q(device=self) if self.pk else Q() if self.virtual_chassis and (self.virtual_chassis.master == self or not if_master): filter |= Q(device__virtual_chassis=self.virtual_chassis, mgmt_only=False) return Interface.objects.filter(filter) diff --git a/netbox/extras/models/configs.py b/netbox/extras/models/configs.py index 425c1386a..6ea2167c2 100644 --- a/netbox/extras/models/configs.py +++ b/netbox/extras/models/configs.py @@ -182,7 +182,7 @@ class ConfigContextModel(models.Model): if not hasattr(self, 'config_context_data'): # The annotation is not available, so we fall back to manually querying for the config context objects - config_context_data = ConfigContext.objects.get_for_object(self, aggregate_data=True) + config_context_data = ConfigContext.objects.get_for_object(self, aggregate_data=True) or [] else: # The attribute may exist, but the annotated value could be None if there is no config context data config_context_data = self.config_context_data or [] diff --git a/requirements.txt b/requirements.txt index 7cbc5534c..788a22f9c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ bleach==6.1.0 -Django==4.2.8 +Django==5.0.1 django-cors-headers==4.3.1 django-debug-toolbar==4.2.0 django-filter==23.5