Vlan group: Removing scope fails via api because scope_type does not allow nulls #7181

Closed
opened 2025-12-29 20:20:14 +01:00 by adam · 3 comments
Owner

Originally created by @amhn on GitHub (Oct 30, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.3.6 && master

Python version

3.10

Steps to Reproduce

  1. Create site
  2. Create Vlan Group with scope
  3. Send {"scope_type": null, "scope_id": null} to /api/ipam/vlan-groups/ method PATCH

Expected Behavior

Scope is unset.

Observed Behavior

An error is returned:

{"scope_type":["This field may not be null."]}
Originally created by @amhn on GitHub (Oct 30, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.3.6 && master ### Python version 3.10 ### Steps to Reproduce 1. Create site 2. Create Vlan Group with scope 3. Send `{"scope_type": null, "scope_id": null}` to `/api/ipam/vlan-groups/` method PATCH ### Expected Behavior Scope is unset. ### Observed Behavior An error is returned: ``` {"scope_type":["This field may not be null."]} ```
adam added the type: bugstatus: accepted labels 2025-12-29 20:20:14 +01:00
adam closed this issue 2025-12-29 20:20:14 +01:00
Author
Owner

@amhn commented on GitHub (Oct 30, 2022):

The following diff allows removing the scope via API:

diff --git a/netbox/ipam/api/serializers.py b/netbox/ipam/api/serializers.py
index fa8b563e9..eff39a418 100644
--- a/netbox/ipam/api/serializers.py
+++ b/netbox/ipam/api/serializers.py
@@ -175,6 +175,7 @@ class VLANGroupSerializer(NetBoxModelSerializer):
         queryset=ContentType.objects.filter(
             model__in=VLANGROUP_SCOPE_TYPES
         ),
+        allow_null=True,
         required=False,
         default=None
     )
@amhn commented on GitHub (Oct 30, 2022): The following diff allows removing the scope via API: ``` diff --git a/netbox/ipam/api/serializers.py b/netbox/ipam/api/serializers.py index fa8b563e9..eff39a418 100644 --- a/netbox/ipam/api/serializers.py +++ b/netbox/ipam/api/serializers.py @@ -175,6 +175,7 @@ class VLANGroupSerializer(NetBoxModelSerializer): queryset=ContentType.objects.filter( model__in=VLANGROUP_SCOPE_TYPES ), + allow_null=True, required=False, default=None ) ```
Author
Owner

@amhn commented on GitHub (Oct 31, 2022):

Same problem and fix with the time_zone attribute of site:

diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py
index 897ee4ca3..cb1edfe1f 100644
--- a/netbox/dcim/api/serializers.py
+++ b/netbox/dcim/api/serializers.py
@@ -130,7 +130,7 @@ class SiteSerializer(NetBoxModelSerializer):
     region = NestedRegionSerializer(required=False, allow_null=True)
     group = NestedSiteGroupSerializer(required=False, allow_null=True)
     tenant = NestedTenantSerializer(required=False, allow_null=True)
-    time_zone = TimeZoneSerializerField(required=False)
+    time_zone = TimeZoneSerializerField(required=False, allow_null=True)
     asns = SerializedPKRelatedField(
         queryset=ASN.objects.all(),
         serializer=NestedASNSerializer,
@amhn commented on GitHub (Oct 31, 2022): Same problem and fix with the time_zone attribute of site: ``` diff --git a/netbox/dcim/api/serializers.py b/netbox/dcim/api/serializers.py index 897ee4ca3..cb1edfe1f 100644 --- a/netbox/dcim/api/serializers.py +++ b/netbox/dcim/api/serializers.py @@ -130,7 +130,7 @@ class SiteSerializer(NetBoxModelSerializer): region = NestedRegionSerializer(required=False, allow_null=True) group = NestedSiteGroupSerializer(required=False, allow_null=True) tenant = NestedTenantSerializer(required=False, allow_null=True) - time_zone = TimeZoneSerializerField(required=False) + time_zone = TimeZoneSerializerField(required=False, allow_null=True) asns = SerializedPKRelatedField( queryset=ASN.objects.all(), serializer=NestedASNSerializer, ```
Author
Owner

@jeremystretch commented on GitHub (Nov 1, 2022):

Same problem and fix with the time_zone attribute of site:

Please open a separate bug report for this.

@jeremystretch commented on GitHub (Nov 1, 2022): > Same problem and fix with the time_zone attribute of site: Please open a separate bug report for this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7181