Site: Removing timezone fails via api because time_zone does not allow nulls #7191

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

Originally created by @amhn on GitHub (Nov 1, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.3.6 & master

Python version

3.10

Steps to Reproduce

  1. Create site with time_zone, e.g. Europe/Berline
  2. Send {"time_zone": null} to /api/dcim/site// method PATCH

Expected Behavior

Time zone is unset.

Observed Behavior

An error is returned:

{"time_zone":["This field may not be null."]}
Originally created by @amhn on GitHub (Nov 1, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.3.6 & master ### Python version 3.10 ### Steps to Reproduce 1. Create site with time_zone, e.g. Europe/Berline 2. Send `{"time_zone": null}` to /api/dcim/site/<id>/ method PATCH ### Expected Behavior Time zone is unset. ### Observed Behavior An error is returned: ``` {"time_zone":["This field may not be null."]} ```
adam added the type: bugstatus: accepted labels 2025-12-29 20:20:19 +01:00
adam closed this issue 2025-12-29 20:20:19 +01:00
Author
Owner

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

Fixed with:

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,

See also #10791

@amhn commented on GitHub (Nov 1, 2022): Fixed with: ``` 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, ``` See also #10791
Author
Owner

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

Thanks!

@jeremystretch commented on GitHub (Nov 1, 2022): Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7191