Просмотр исходного кода

Fixes #6081: Fix interface connections REST API endpoint

jeremystretch 4 лет назад
Родитель
Сommit
ae3527df16
3 измененных файлов с 4 добавлено и 1 удалено
  1. 1 0
      docs/release-notes/version-2.10.md
  2. 1 1
      netbox/dcim/api/serializers.py
  3. 2 0
      netbox/dcim/api/views.py

+ 1 - 0
docs/release-notes/version-2.10.md

@@ -13,6 +13,7 @@
 
 * [#5805](https://github.com/netbox-community/netbox/issues/5805) - Fix missing custom field filters for cables, rack reservations
 * [#6073](https://github.com/netbox-community/netbox/issues/6073) - Permit users to manage their own REST API tokens without needing explicit permission
+* [#6081](https://github.com/netbox-community/netbox/issues/6081) - Fix interface connections REST API endpoint
 
 ---
 

+ 1 - 1
netbox/dcim/api/serializers.py

@@ -779,7 +779,7 @@ class CablePathSerializer(serializers.ModelSerializer):
 
 class InterfaceConnectionSerializer(ValidatedModelSerializer):
     interface_a = serializers.SerializerMethodField()
-    interface_b = NestedInterfaceSerializer(source='connected_endpoint')
+    interface_b = NestedInterfaceSerializer(source='_path.destination')
     connected_endpoint_reachable = serializers.SerializerMethodField(read_only=True)
 
     class Meta:

+ 2 - 0
netbox/dcim/api/views.py

@@ -2,6 +2,7 @@ import socket
 from collections import OrderedDict
 
 from django.conf import settings
+from django.contrib.contenttypes.models import ContentType
 from django.db.models import F
 from django.http import HttpResponseForbidden, HttpResponse
 from django.shortcuts import get_object_or_404
@@ -580,6 +581,7 @@ class PowerConnectionViewSet(ListModelMixin, GenericViewSet):
 class InterfaceConnectionViewSet(ListModelMixin, GenericViewSet):
     queryset = Interface.objects.prefetch_related('device', '_path').filter(
         # Avoid duplicate connections by only selecting the lower PK in a connected pair
+        _path__destination_type=ContentType.objects.get_by_natural_key('dcim', 'interface'),
         _path__destination_id__isnull=False,
         pk__lt=F('_path__destination_id')
     )