Unable to place another device in rack non-racked via REST API
Deployment Type
Self-hosted
NetBox Version
4.0.5
Python Version
3.11
Steps to Reproduce
- Ensure some site exists
- Ensure some rack exists in the site (id=1 in example)
- Create first device in rack non-racked
- Create second device in the site (id=2 in example)
- Try placing the the device in the rack non-racked via the API
curl -X PATCH -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"rack":1}' https://netbox.example.org/api/dcim/devices/2/
Expected Behaviour
API request should be successful (HTTP 200), device should be placed in the rack non-racked.
Observed Behaviour
API request fails (HTTP 400), (formatting applied by me):
{
"non_field_errors": [
"The fields rack, position, face must make a unique set."
]
}
This works fine via the UI though.
I believe you have to set the device position within the rack as well as the rack face in order to successfully add a device to a rack. That is also what the error message is trying to tell you.
@v0tti is correct: Just as in the UI, you need to specify a unit and face when assigning a device to a rack. I'll leave this open for anyone who would like to work on improving the error message.
I did not specify rack and position on purpose as the device should be "Not racked". Sorry I didn't state that clearer.
Using GET on a "Not racked" device returns null for both attributes. Explicitly providing both attributes at PATCH results in the same error.
Still: for me it's possible to not provide position and face to place a device in a rack "Not racked" in the UI.
@FestplattenSchnitzel Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0.5. Please re-confirm the reported behavior on the current stable release and adjust your post above as necessary. Remember to provide detailed steps that someone else can follow using a clean installation of NetBox to reproduce the issue. Remember to include the steps taken to create any initial objects or other data.
I tried with two different devices and used your curl command and in both cases it set the rack correctly without an error message (these did not have any rack assigned previously).
Ah, I can reproduce this works fine with newly created sites and racks. However, if I create a new device in a site that exists for a long time™ already:
curl -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"role":1,"device_type":1,"site":1,"status":"planned"}' https://netbox.example.org/api/dcim/devices/
then try to place ("not racked") that in a rack in the same site (also exists since long ago):
curl -sX PATCH -H "authorization: Token TOKEN" -H 'Content-Type: application/json' -d '{"rack":2}' https://netbox.example.org/api/dcim/devices/2222/
I get the error from the original comment.
OK, the problem is you can't place a second device in a rack non-racked when there is a first one already. The old racks all had at least one non-racked device contrary to the newly created ones, which explains the behaviour from my last comment.
With a little more creativity one could've guessed that at the very beginning … :D
Will update initial comment and title soon …
This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
This issue is being closed as no further information has been provided. If you would like to revisit this topic, please first modify your original post to include all the requested detail, and then ask that the issue be reopened.
@arthanson could you please take another look at this? I can reproduce the error pattern too. Due to the issue one of our applications no longer works.
Same problem can't move device with rack and empty position and face