Can't place multiple devices in rack with non-racked device (using API) #10385

Closed
opened 2025-12-29 21:30:45 +01:00 by adam · 5 comments
Owner

Originally created by @markusmarkusz on GitHub (Oct 18, 2024).

Originally assigned to: @jeremystretch on GitHub.

Deployment Type

Self-hosted

Triage priority

This is preventing me from using NetBox

NetBox Version

v4.1.4

Python Version

3.12

Steps to Reproduce

  1. Create site
  2. Create rack in the site (for example with id = 1)
  3. Create first non-racked device in rack
  4. Create second device
  5. Try placing the the device in the rack as non-racked device via API

Important: I can only reproduce the problem using the REST API.

API Calls

# Create first device, non-racked in the rack (remember the id, ensure there are no devices non-racked before)
curl -X POST -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"device_type":116,"role":25,"site":1,"rack":168}' https://netbox.example.org/api/dcim/devices/ | jq .id
# Create second device, floating around in the site
curl -X POST -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"device_type":116,"role":25,"site":1}' https://netbox.example.org/api/dcim/devices/ | jq . | less
# Try moving the device to the rack of the first device non-racked (fails)
curl -X PATCH -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"rack":168}' https://netbox.example.org/api/dcim/devices/$ID_FROM_THE_FIRST_COMMAND/ | jq . | less
# Run first command again, creating another device, doesn't fail strangely
curl -X POST -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"device_type":116,"role":25,"site":1,"rack":168}' https://netbox.example.org/api/dcim/devices/ | jq .id

Expected Behavior

Device should be placed in the rack as non-racked.

Observed Behavior

HTTP 400 Error Code

{"non_field_errors": ["The fields rack, position, face must make a unique set."]}
Originally created by @markusmarkusz on GitHub (Oct 18, 2024). Originally assigned to: @jeremystretch on GitHub. ### Deployment Type Self-hosted ### Triage priority This is preventing me from using NetBox ### NetBox Version v4.1.4 ### Python Version 3.12 ### Steps to Reproduce 1. Create site 2. Create rack in the site (for example with id = 1) 3. Create first non-racked device in rack 4. Create second device 5. Try placing the the device in the rack as non-racked device via API Important: I can only reproduce the problem using the REST API. #### API Calls ``` # Create first device, non-racked in the rack (remember the id, ensure there are no devices non-racked before) curl -X POST -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"device_type":116,"role":25,"site":1,"rack":168}' https://netbox.example.org/api/dcim/devices/ | jq .id # Create second device, floating around in the site curl -X POST -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"device_type":116,"role":25,"site":1}' https://netbox.example.org/api/dcim/devices/ | jq . | less # Try moving the device to the rack of the first device non-racked (fails) curl -X PATCH -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"rack":168}' https://netbox.example.org/api/dcim/devices/$ID_FROM_THE_FIRST_COMMAND/ | jq . | less # Run first command again, creating another device, doesn't fail strangely curl -X POST -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"device_type":116,"role":25,"site":1,"rack":168}' https://netbox.example.org/api/dcim/devices/ | jq .id ``` ### Expected Behavior Device should be placed in the rack as non-racked. ### Observed Behavior HTTP 400 Error Code ``` {"non_field_errors": ["The fields rack, position, face must make a unique set."]} ```
adam added the type: bugstatus: acceptednetboxseverity: medium labels 2025-12-29 21:30:45 +01:00
adam closed this issue 2025-12-29 21:30:45 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 18, 2024):

Please revise your post above to include the specific attributes of the devices you're creating and the API requests you're sending.

@jeremystretch commented on GitHub (Oct 18, 2024): Please revise your post above to include the specific attributes of the devices you're creating and the API requests you're sending.
Author
Owner

@markusmarkusz commented on GitHub (Oct 20, 2024):

Hello @jeremystretch, thank you for your response. I adjusted my post and added the API calls.

@markusmarkusz commented on GitHub (Oct 20, 2024): Hello @jeremystretch, thank you for your response. I adjusted my post and added the API calls.
Author
Owner

@jeremystretch commented on GitHub (Oct 23, 2024):

I was able to replicate this. The bug seems to stem from the absence of the face and position fields in the PATCH data. This looks related to a bug in Django REST Framework 3.15, but I haven't been able to dig further yet.

@jeremystretch commented on GitHub (Oct 23, 2024): I was able to replicate this. The bug seems to stem from the absence of the `face` and `position` fields in the PATCH data. This looks related to a [bug in Django REST Framework 3.15](https://github.com/encode/django-rest-framework/issues/9410), but I haven't been able to dig further yet.
Author
Owner

@bctiemann commented on GitHub (Oct 31, 2024):

I tried adding default=None to the face and position model fields on Device (as recommended in that DRF thread) but it doesn't seem to help.

It's possible it's not exactly the same issue as that DRF bug, or a different side effect of the same change, but in either case it's unclear whether the DRF behavior will be reverted or if this is a breaking change that they will stick with.

@bctiemann commented on GitHub (Oct 31, 2024): I tried adding `default=None` to the `face` and `position` model fields on `Device` (as recommended in that DRF thread) but it doesn't seem to help. It's possible it's not exactly the same issue as that DRF bug, or a different side effect of the same change, but in either case it's unclear whether the DRF behavior will be reverted or if this is a breaking change that they will stick with.
Author
Owner

@markusmarkusz commented on GitHub (Nov 4, 2024):

Would it be an option to downgrade the Django REST Framework to an older version? If I got it correctly from the issue, a fix is at the moment not in sight.

@markusmarkusz commented on GitHub (Nov 4, 2024): Would it be an option to downgrade the Django REST Framework to an older version? If I got it correctly from the issue, a fix is at the moment not in sight.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10385