Skip to content

Commit cc099e8

Browse files
authored
Fixes #19520: restores ability to set Prefix.scope via API (#19588)
1 parent a97b438 commit cc099e8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

netbox/dcim/models/mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Meta:
8585
abstract = True
8686

8787
def clean(self):
88-
if self.scope_type and not self.scope:
88+
if self.scope_type and not (self.scope or self.scope_id):
8989
scope_type = self.scope_type.model_class()
9090
raise ValidationError({
9191
'scope': _(

netbox/ipam/tests/test_api.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33

4+
from django.test import tag
45
from django.urls import reverse
56
from netaddr import IPNetwork
67
from rest_framework import status
@@ -383,6 +384,18 @@ def setUpTestData(cls):
383384
)
384385
Prefix.objects.bulk_create(prefixes)
385386

387+
@tag('regression')
388+
def test_clean_validates_scope(self):
389+
prefix = Prefix.objects.first()
390+
site = Site.objects.create(name='Test Site', slug='test-site')
391+
392+
data = {'scope_type': 'dcim.site', 'scope_id': site.id}
393+
url = reverse('ipam-api:prefix-detail', kwargs={'pk': prefix.pk})
394+
self.add_permissions('ipam.change_prefix')
395+
396+
response = self.client.patch(url, data, format='json', **self.header)
397+
self.assertHttpStatus(response, status.HTTP_200_OK)
398+
386399
def test_list_available_prefixes(self):
387400
"""
388401
Test retrieval of all available prefixes within a parent prefix.

0 commit comments

Comments
 (0)