From abf32d7587a979731aa78ef7246eb21f0cfb9c56 Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 13 May 2024 15:59:24 -0700 Subject: [PATCH] 14606 add id to GenericObjectSerializer --- netbox/dcim/tests/test_api.py | 6 ++++++ netbox/netbox/api/serializers/generic.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/tests/test_api.py b/netbox/dcim/tests/test_api.py index 52b850b24..b4aaadea3 100644 --- a/netbox/dcim/tests/test_api.py +++ b/netbox/dcim/tests/test_api.py @@ -2005,10 +2005,12 @@ class CableTest(APIViewTestCases.APIViewTestCase): cls.create_data = [ { 'a_terminations': [{ + 'id': interfaces[4].pk, 'object_type': 'dcim.interface', 'object_id': interfaces[4].pk, }], 'b_terminations': [{ + 'id': interfaces[14].pk, 'object_type': 'dcim.interface', 'object_id': interfaces[14].pk, }], @@ -2016,10 +2018,12 @@ class CableTest(APIViewTestCases.APIViewTestCase): }, { 'a_terminations': [{ + 'id': interfaces[5].pk, 'object_type': 'dcim.interface', 'object_id': interfaces[5].pk, }], 'b_terminations': [{ + 'id': interfaces[15].pk, 'object_type': 'dcim.interface', 'object_id': interfaces[15].pk, }], @@ -2027,10 +2031,12 @@ class CableTest(APIViewTestCases.APIViewTestCase): }, { 'a_terminations': [{ + 'id': interfaces[6].pk, 'object_type': 'dcim.interface', 'object_id': interfaces[6].pk, }], 'b_terminations': [{ + 'id': interfaces[16].pk, 'object_type': 'dcim.interface', 'object_id': interfaces[16].pk, }], diff --git a/netbox/netbox/api/serializers/generic.py b/netbox/netbox/api/serializers/generic.py index 6b693c33d..c69a97fd5 100644 --- a/netbox/netbox/api/serializers/generic.py +++ b/netbox/netbox/api/serializers/generic.py @@ -16,7 +16,7 @@ class GenericObjectSerializer(serializers.Serializer): """ Minimal representation of some generic object identified by ContentType and PK. """ - id = serializers.IntegerField() + id = serializers.IntegerField(read_only=True, required=False) object_type = ContentTypeField( queryset=ContentType.objects.all() )