Erroneous Group Requirement on Rack Endpoint #1919

Closed
opened 2025-12-29 17:20:34 +01:00 by adam · 1 comment
Owner

Originally created by @zachmoody on GitHub (Aug 8, 2018).

Environment

  • Python version: 2.7
  • NetBox version: 2.4.1

Steps to Reproduce

Create a rack in the API yields a 400 that says group is required.

Expected Behavior

Create the rack without a group association.

Observed Behavior

curl -XPOST -H "Content-type: application/json" \
	-H "Authorization: Token 1234" \
	-d '{"name": "1234", "site":11}' \
	http://localhost:8000/api/dcim/racks/

{"group":["This field is required."]}
Originally created by @zachmoody on GitHub (Aug 8, 2018). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 2.7 * NetBox version: 2.4.1 <!-- Describe in detail the steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). --> ### Steps to Reproduce Create a rack in the API yields a 400 that says group is required. <!-- What did you expect to happen? --> ### Expected Behavior Create the rack without a group association. <!-- What happened instead? --> ### Observed Behavior ``` curl -XPOST -H "Content-type: application/json" \ -H "Authorization: Token 1234" \ -d '{"name": "1234", "site":11}' \ http://localhost:8000/api/dcim/racks/ {"group":["This field is required."]} ```
adam added the type: bugstatus: accepted labels 2025-12-29 17:20:34 +01:00
adam closed this issue 2025-12-29 17:20:35 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 8, 2018):

This is related to #238. The UniqueTogetherValidator on the Rack serializer is registering group as a required field:

UniqueTogetherValidator(queryset=Rack.objects.all(), fields=('group', 'name'))

This is due to a bug where unique validation for some reason can't happen against null fields. From the DRF docs:

Note: The UniqueTogetherValidation class always imposes an implicit constraint that all the fields it applies to are always treated as required. Fields with default values are an exception to this as they always supply a value even when omitted from user input.

@jeremystretch commented on GitHub (Aug 8, 2018): This is related to #238. The UniqueTogetherValidator on the Rack serializer is registering `group` as a required field: ``` UniqueTogetherValidator(queryset=Rack.objects.all(), fields=('group', 'name')) ``` This is due to a bug where unique validation for some reason can't happen against null fields. From [the DRF docs](http://www.django-rest-framework.org/api-guide/validators/#uniquetogethervalidator): > Note: The UniqueTogetherValidation class always imposes an implicit constraint that all the fields it applies to are always treated as required. Fields with default values are an exception to this as they always supply a value even when omitted from user input.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1919