From ae93ce848b957b606b4fbc255961eb7a8a2c2e02 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Tue, 22 Oct 2024 18:42:33 -0400 Subject: [PATCH] Explicitly prefetch policy in graphql --- netbox/ipam/graphql/types.py | 2 +- netbox/ipam/models/vlans.py | 6 ++++-- netbox/ipam/tests/test_api.py | 5 ----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/netbox/ipam/graphql/types.py b/netbox/ipam/graphql/types.py index 9b3becc17..ef50138c2 100644 --- a/netbox/ipam/graphql/types.py +++ b/netbox/ipam/graphql/types.py @@ -291,7 +291,7 @@ class VLANTranslationPolicyType(NetBoxObjectType): filters=VLANTranslationRuleFilter ) class VLANTranslationRuleType(NetBoxObjectType): - policy: Annotated["VLANTranslationPolicyType", strawberry.lazy('ipam.graphql.types')] | None + policy: Annotated["VLANTranslationPolicyType", strawberry.lazy('ipam.graphql.types')] = strawberry_django.field(select_related=["policy"]) @strawberry_django.type( diff --git a/netbox/ipam/models/vlans.py b/netbox/ipam/models/vlans.py index dbc3a9a78..1d14615c1 100644 --- a/netbox/ipam/models/vlans.py +++ b/netbox/ipam/models/vlans.py @@ -315,6 +315,9 @@ class VLANTranslationRule(NetBoxModel): ), help_text=_("Numeric VLAN ID (1-4094)") ) + prerequisite_models = ( + 'ipam.VLANTranslationPolicy', + ) class Meta: verbose_name = _('VLAN translation rule') @@ -331,8 +334,7 @@ class VLANTranslationRule(NetBoxModel): ) def __str__(self): - return f'{self.local_vid} -> {self.remote_vid}' - # return f'{self.local_vid} -> {self.remote_vid} ({self.policy})' + return f'{self.local_vid} -> {self.remote_vid} ({self.policy})' def to_objectchange(self, action): objectchange = super().to_objectchange(action) diff --git a/netbox/ipam/tests/test_api.py b/netbox/ipam/tests/test_api.py index 9569b58ff..8a08a7143 100644 --- a/netbox/ipam/tests/test_api.py +++ b/netbox/ipam/tests/test_api.py @@ -1065,10 +1065,6 @@ class VLANTranslationPolicyTest(APIViewTestCases.APIViewTestCase): class VLANTranslationRuleTest(APIViewTestCases.APIViewTestCase): model = VLANTranslationRule brief_fields = ['id', 'local_vid', 'policy', 'remote_vid',] - bulk_update_data = { - 'policy': '109', - 'remote_vid': '209', - } @classmethod def setUpTestData(cls): @@ -1103,7 +1099,6 @@ class VLANTranslationRuleTest(APIViewTestCases.APIViewTestCase): ), ) VLANTranslationRule.objects.bulk_create(vlan_translation_rules) - print(VLANTranslationRule.objects.all().values('id', 'policy')) cls.create_data = [ {