mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-08 21:02:18 -06:00
Fixes #4496: Fix exception when validating certain models via REST API
This commit is contained in:
@@ -90,8 +90,7 @@ class VLANGroupSerializer(ValidatedModelSerializer):
|
||||
if data.get('site', None):
|
||||
for field in ['name', 'slug']:
|
||||
validator = UniqueTogetherValidator(queryset=VLANGroup.objects.all(), fields=('site', field))
|
||||
validator.set_context(self)
|
||||
validator(data)
|
||||
validator(data, self)
|
||||
|
||||
# Enforce model validation
|
||||
super().validate(data)
|
||||
@@ -122,8 +121,7 @@ class VLANSerializer(TaggitSerializer, CustomFieldModelSerializer):
|
||||
if data.get('group', None):
|
||||
for field in ['vid', 'name']:
|
||||
validator = UniqueTogetherValidator(queryset=VLAN.objects.all(), fields=('group', field))
|
||||
validator.set_context(self)
|
||||
validator(data)
|
||||
validator(data, self)
|
||||
|
||||
# Enforce model validation
|
||||
super().validate(data)
|
||||
|
||||
@@ -785,6 +785,7 @@ class VLANGroupTest(APITestCase):
|
||||
|
||||
super().setUp()
|
||||
|
||||
self.site1 = Site.objects.create(name='Test Site 1', slug='test-site-1')
|
||||
self.vlangroup1 = VLANGroup.objects.create(name='Test VLAN Group 1', slug='test-vlan-group-1')
|
||||
self.vlangroup2 = VLANGroup.objects.create(name='Test VLAN Group 2', slug='test-vlan-group-2')
|
||||
self.vlangroup3 = VLANGroup.objects.create(name='Test VLAN Group 3', slug='test-vlan-group-3')
|
||||
@@ -818,6 +819,7 @@ class VLANGroupTest(APITestCase):
|
||||
data = {
|
||||
'name': 'Test VLAN Group 4',
|
||||
'slug': 'test-vlan-group-4',
|
||||
'site': self.site1.pk,
|
||||
}
|
||||
|
||||
url = reverse('ipam-api:vlangroup-list')
|
||||
@@ -886,10 +888,10 @@ class VLANTest(APITestCase):
|
||||
|
||||
super().setUp()
|
||||
|
||||
self.group1 = VLANGroup.objects.create(name='Test VLAN Group 1', slug='test-vlan-group-1')
|
||||
self.vlan1 = VLAN.objects.create(vid=1, name='Test VLAN 1')
|
||||
self.vlan2 = VLAN.objects.create(vid=2, name='Test VLAN 2')
|
||||
self.vlan3 = VLAN.objects.create(vid=3, name='Test VLAN 3')
|
||||
|
||||
self.prefix1 = Prefix.objects.create(prefix=IPNetwork('192.168.1.0/24'))
|
||||
|
||||
def test_get_vlan(self):
|
||||
@@ -921,6 +923,7 @@ class VLANTest(APITestCase):
|
||||
data = {
|
||||
'vid': 4,
|
||||
'name': 'Test VLAN 4',
|
||||
'group': self.group1.pk,
|
||||
}
|
||||
|
||||
url = reverse('ipam-api:vlan-list')
|
||||
|
||||
Reference in New Issue
Block a user