Sfoglia il codice sorgente

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 <jstretch@netboxlabs.com>
Arthur Hanson 2 anni fa
parent
commit
58227293f3

+ 1 - 1
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

+ 1 - 3
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 *

+ 6 - 2
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} "

+ 1 - 1
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)

+ 1 - 1
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 []

+ 1 - 1
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