Skip to content

Commit fd2bcda

Browse files
authored
Fixes #18991: AttributeError: NoneType object has not attribute model (#19006)
1 parent 817d7ef commit fd2bcda

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

netbox/dcim/tests/test_api.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22

3-
from django.test import override_settings
3+
from django.test import override_settings, tag
44
from django.urls import reverse
55
from django.utils.translation import gettext as _
66
from rest_framework import status
@@ -1904,6 +1904,27 @@ def setUpTestData(cls):
19041904
},
19051905
]
19061906

1907+
@tag('regression') # Issue #18991
1908+
def test_front_port_paths(self):
1909+
device = Device.objects.first()
1910+
rear_port = RearPort.objects.create(
1911+
device=device, name='Rear Port 10', type=PortTypeChoices.TYPE_8P8C
1912+
)
1913+
interface1 = Interface.objects.create(device=device, name='Interface 1')
1914+
front_port = FrontPort.objects.create(
1915+
device=device,
1916+
name='Rear Port 10',
1917+
type=PortTypeChoices.TYPE_8P8C,
1918+
rear_port=rear_port,
1919+
)
1920+
Cable.objects.create(a_terminations=[interface1], b_terminations=[front_port])
1921+
1922+
self.add_permissions(f'dcim.view_{self.model._meta.model_name}')
1923+
url = reverse(f'dcim-api:{self.model._meta.model_name}-paths', kwargs={'pk': front_port.pk})
1924+
response = self.client.get(url, **self.header)
1925+
1926+
self.assertHttpStatus(response, status.HTTP_200_OK)
1927+
19071928

19081929
class RearPortTest(APIViewTestCases.APIViewTestCase):
19091930
model = RearPort
@@ -1947,6 +1968,23 @@ def setUpTestData(cls):
19471968
},
19481969
]
19491970

1971+
@tag('regression') # Issue #18991
1972+
def test_rear_port_paths(self):
1973+
device = Device.objects.first()
1974+
interface1 = Interface.objects.create(device=device, name='Interface 1')
1975+
rear_port = RearPort.objects.create(
1976+
device=device,
1977+
name='Rear Port 10',
1978+
type=PortTypeChoices.TYPE_8P8C,
1979+
)
1980+
Cable.objects.create(a_terminations=[interface1], b_terminations=[rear_port])
1981+
1982+
self.add_permissions(f'dcim.view_{self.model._meta.model_name}')
1983+
url = reverse(f'dcim-api:{self.model._meta.model_name}-paths', kwargs={'pk': rear_port.pk})
1984+
response = self.client.get(url, **self.header)
1985+
1986+
self.assertHttpStatus(response, status.HTTP_200_OK)
1987+
19501988

19511989
class ModuleBayTest(APIViewTestCases.APIViewTestCase):
19521990
model = ModuleBay

netbox/utilities/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ class GenericArrayForeignKey(FieldCacheMixin, models.Field):
198198
Provide a generic many-to-many relation through an 2d array field
199199
"""
200200

201-
many_to_many = True
201+
many_to_many = False
202202
many_to_one = False
203-
one_to_many = False
203+
one_to_many = True
204204
one_to_one = False
205205

206206
def __init__(self, field, for_concrete_model=True):

0 commit comments

Comments
 (0)