Unable to create Racked Device through REST API when defining Variable "face" #3590

Closed
opened 2025-12-29 18:30:02 +01:00 by adam · 1 comment
Owner

Originally created by @2muchgit on GitHub (Apr 21, 2020).

Environment

  • Python version: 3.7.7
  • NetBox version: 2.8.0
  • we are using netboxcommunity/netbox:v2.8.0-ldap

Steps to Reproduce

  1. Create all necessary Objects for creating device:
  • Device Type
  • Device Role
  • Site
  • Rack
  1. Creating a Device:
    curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": 1, "face": 0, "status": 1 }'

Expected Behavior

Receive HTTP 200 from the web-server.
Device with name "teststuff" should be created and mounted to its rack position

Observed Behavior

Netbox:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/rest_framework/viewsets.py", line 114, in view
return self.dispatch(request, *args, **kwargs)
File "/opt/netbox/netbox/utilities/api.py", line 330, in dispatch
return super().dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 505, in dispatch
response = self.handle_exception(exc)
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 465, in handle_exception
self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
raise exc
File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 502, in dispatch
response = handler(request, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/rest_framework/mixins.py", line 18, in create
serializer.is_valid(raise_exception=True)
File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 234, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 436, in run_validation
value = self.validate(value)
File "/opt/netbox/netbox/dcim/api/serializers.py", line 398, in validate
validator.set_context(self)

Exception Type: AttributeError at /api/dcim/devices/ Exception Value: 'UniqueTogetherValidator' object has no attribute 'set_context'

Web-server:
[21/Apr/2020:10:12:15 +0000] "POST /api/dcim/devices/ HTTP/1.0" 500 22793 "-" "curl/7.58.0"

Notes

When sending the request, "face" seems to be the only argument whose value is not being accepted:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": 1, "face": "front", "status": 1 }'

Using "front" or "rear" Returns the same error as previously shown.

Any other value for "face" returns a proper response:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": "2", "face":"bla", "status": 1 }'

{ "face": [ "bla is not a valid choice." ] }

curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": "2", "face":"", "status": 1 }'

{ "face": [ "Must specify rack face when defining rack position." ] }

curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": "2", "face":{"id": 0}, "status": 1 }'

{ "face": [ "Value must be passed directly (e.g. \"foo\": 123); do not use a dictionary or list." ] }

Originally created by @2muchgit on GitHub (Apr 21, 2020). ### Environment * Python version: 3.7.7 * NetBox version: 2.8.0 * we are using netboxcommunity/netbox:v2.8.0-ldap ### Steps to Reproduce 1. Create all necessary Objects for creating device: - Device Type - Device Role - Site - Rack 2. Creating a Device: `curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": 1, "face": 0, "status": 1 }'` <!-- What did you expect to happen? --> ### Expected Behavior Receive HTTP 200 from the web-server. Device with name "teststuff" should be created and mounted to its rack position <!-- What happened instead? --> ### Observed Behavior Netbox: Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/rest_framework/viewsets.py", line 114, in view return self.dispatch(request, *args, **kwargs) File "/opt/netbox/netbox/utilities/api.py", line 330, in dispatch return super().dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 505, in dispatch response = self.handle_exception(exc) File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 465, in handle_exception self.raise_uncaught_exception(exc) File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception raise exc File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 502, in dispatch response = handler(request, *args, **kwargs) File "/usr/local/lib/python3.7/site-packages/rest_framework/mixins.py", line 18, in create serializer.is_valid(raise_exception=True) File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 234, in is_valid self._validated_data = self.run_validation(self.initial_data) File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 436, in run_validation value = self.validate(value) File "/opt/netbox/netbox/dcim/api/serializers.py", line 398, in validate validator.set_context(self) `Exception Type: AttributeError at /api/dcim/devices/ Exception Value: 'UniqueTogetherValidator' object has no attribute 'set_context'` Web-server: `[21/Apr/2020:10:12:15 +0000] "POST /api/dcim/devices/ HTTP/1.0" 500 22793 "-" "curl/7.58.0"` ### Notes When sending the request, "face" seems to be the only argument whose value is not being accepted: `curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": 1, "face": "front", "status": 1 }'` Using "front" or "rear" Returns the same error as previously shown. Any other value for "face" returns a proper response: `curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": "2", "face":"bla", "status": 1 }'` `{ "face": [ "bla is not a valid choice." ] }` `curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": "2", "face":"", "status": 1 }'` `{ "face": [ "Must specify rack face when defining rack position." ] }` `curl -X POST -H "Content-Type: application/json" -H "Authorization: Token <TOKEN>" -H "Accept: application/json; indent=4" http://netbox.test/api/dcim/devices/ --data '{ "name": "teststuff", "display_name": "teststuff", "device_type": { "id": 43 }, "device_role": { "id": 2 }, "site": { "id": 27 }, "rack": { "id": 300 }, "position": "2", "face":{"id": 0}, "status": 1 }'` `{ "face": [ "Value must be passed directly (e.g. \"foo\": 123); do not use a dictionary or list." ] }`
adam closed this issue 2025-12-29 18:30:02 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 21, 2020):

Looks to be the same issue as #4496. Will be fixed in v2.8.1.

@jeremystretch commented on GitHub (Apr 21, 2020): Looks to be the same issue as #4496. Will be fixed in v2.8.1.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3590