OPTIONS requests for list API endpoints raises an exception #4364

Closed
opened 2025-12-29 18:35:14 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Dec 16, 2020).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.9
  • NetBox version: 2.10.0

Steps to Reproduce

  1. Make an OPTIONS request to a REST API list endpoint. For example:
curl -X OPTIONS \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://netbox/api/dcim/devices/

(Note that all REST API endpoints are affected, not just the one above.)

Expected Behavior

The response should return metadata for the endpoint. An example is below.

{
    "name": "Device",
    "description": "",
    "renders": [
        "application/json",
        "text/html"
    ],
    "parses": [
        "application/json",
        "application/x-www-form-urlencoded",
        "multipart/form-data"
    ],
    "actions": {
        "POST": {
...

Observed Behavior

An exception is raised:

Exception Type: AssertionError at /api/dcim/devices/
Exception Value: Expected view DeviceViewSet to be called with a URL keyword argument named "pk". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly.

It appears that the introduction of bulk update support poses a problem when rendering metadata for the endpoint, since the metadata class calls get_object() when evaluating fields for POST and PUT requests.

Originally created by @jeremystretch on GitHub (Dec 16, 2020). Originally assigned to: @jeremystretch on GitHub. ### Environment * Python version: 3.6.9 * NetBox version: 2.10.0 ### Steps to Reproduce 1. Make an `OPTIONS` request to a REST API list endpoint. For example: ``` curl -X OPTIONS \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://netbox/api/dcim/devices/ ``` (Note that all REST API endpoints are affected, not just the one above.) ### Expected Behavior The response should return metadata for the endpoint. An example is below. ``` { "name": "Device", "description": "", "renders": [ "application/json", "text/html" ], "parses": [ "application/json", "application/x-www-form-urlencoded", "multipart/form-data" ], "actions": { "POST": { ... ``` ### Observed Behavior An exception is raised: ``` Exception Type: AssertionError at /api/dcim/devices/ Exception Value: Expected view DeviceViewSet to be called with a URL keyword argument named "pk". Fix your URL conf, or set the `.lookup_field` attribute on the view correctly. ``` It appears that the introduction of bulk update support poses a problem when rendering metadata for the endpoint, since the metadata class calls `get_object()` when evaluating fields for `POST` and `PUT` requests.
adam added the type: bugstatus: accepted labels 2025-12-29 18:35:14 +01:00
adam closed this issue 2025-12-29 18:35:14 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4364