Skip to content

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

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

Closed
2muchgit opened this issue Apr 21, 2020 · 1 comment
Closed

Comments

@2muchgit
Copy link

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." ] }

@2muchgit 2muchgit changed the title Unable to create Racked Device through REST API when defining Object "face" Unable to create Racked Device through REST API when defining Variable "face" Apr 21, 2020
@jeremystretch
Copy link
Member

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants