Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
amhn opened this issue Apr 6, 2023 · 0 comments
Assignees
Labels
beta Concerns a bug/feature in a beta release status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@amhn
Copy link
Contributor

amhn commented Apr 6, 2023

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.

@amhn amhn added the type: bug A confirmed report of unexpected behavior in the application label Apr 6, 2023
@jeremystretch jeremystretch added the beta Concerns a bug/feature in a beta release label Apr 7, 2023
@arthanson arthanson self-assigned this Apr 18, 2023
@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Apr 21, 2023
jeremystretch added a commit that referenced this issue Apr 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beta Concerns a bug/feature in a beta release status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants