Ipaddress model does not accept null value for role, but serializer does (regression in 3.5-beta) #7874

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

Originally created by @amhn on GitHub (Apr 6, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.5-beta

Python version

3.10

Steps to Reproduce

  1. POST the following to /api/ipam/ip-addresses/:
{
  "address": "127.0.0.2/8",
  "status": "active",
  "role": null
}

Expected Behavior

IP address is created with role = '' (as in 3.4) or role = null

Observed Behavior

Internal Server Error: /api/ipam/ip-addresses/
Traceback (most recent call last):
  File "/home/andy/python/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.NotNullViolation: null value in column "role" of relation "ipam_ipaddress" violates not-null constraint
DETAIL:  Failing row contains (2023-04-06 19:31:31.261817+00, 2023-04-06 19:31:31.26183+00, {}, 3, 127.0.0.2/8, active, null, null, , , null, null, null, null, ).

This is caused by adding "allow_null=True" to the role field in IPAddressSerializer in the beta code. Without allow_null the serializer silently changes the null value to '' which does not raise the database exception.

Maybe changing the database field to also allow null values is the best option here since a GET request already returns null for an empty ('') value in the database.

Originally created by @amhn on GitHub (Apr 6, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.5-beta ### Python version 3.10 ### Steps to Reproduce 1. POST the following to /api/ipam/ip-addresses/: ```json { "address": "127.0.0.2/8", "status": "active", "role": null } ``` ### Expected Behavior IP address is created with role = '' (as in 3.4) or role = null ### Observed Behavior ``` Internal Server Error: /api/ipam/ip-addresses/ Traceback (most recent call last): File "/home/andy/python/netbox/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) psycopg2.errors.NotNullViolation: null value in column "role" of relation "ipam_ipaddress" violates not-null constraint DETAIL: Failing row contains (2023-04-06 19:31:31.261817+00, 2023-04-06 19:31:31.26183+00, {}, 3, 127.0.0.2/8, active, null, null, , , null, null, null, null, ). ``` This is caused by adding "allow_null=True" to the role field in IPAddressSerializer in the beta code. Without allow_null the serializer silently changes the null value to '' which does not raise the database exception. Maybe changing the database field to also allow null values is the best option here since a GET request already returns null for an empty ('') value in the database.
adam added the type: bugstatus: acceptedbeta labels 2025-12-29 20:29:14 +01:00
adam closed this issue 2025-12-29 20:29:15 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7874