Skip to content

OPTIONS requests for list API endpoints raises an exception #5470

@jeremystretch

Description

@jeremystretch

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.

Metadata

Metadata

Assignees

Labels

status: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions