"Invalid data" error on certain nested API serializers #1899

Closed
opened 2025-12-29 17:20:12 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Aug 6, 2018).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.4.0

Steps to Reproduce

This is an extension of the issue reported in #2299 during the v2.4 beta. Several nested API serializers have been identified as improperly handling posted data. Specifically, they expect a dictionary representation of an object rather than an integer (primary key). For example:

curl -X PATCH \
-H "Authorization: Token <TOKEN>" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://localhost:8000/api/dcim/devices/<pk>/ \
--data '{"cluster": 123}'

The following models and fields have been identified as affected by this bug:

  • Device: cluster, primary_ip4, primary_ip6, virtual_chassis
  • VirtualMachine: primary_ip4, primary_ip6

Expected Behavior

The device should be assigned to the specified cluster.

Observed Behavior

The request yields the following validation error:

{
    "cluster": {
        "non_field_errors": [
            "Invalid data. Expected a dictionary, but got int."
        ]
    }
}
Originally created by @jeremystretch on GitHub (Aug 6, 2018). ### Environment * Python version: 3.5.2 * NetBox version: 2.4.0 ### Steps to Reproduce This is an extension of the issue reported in #2299 during the v2.4 beta. Several nested API serializers have been identified as improperly handling posted data. Specifically, they expect a dictionary representation of an object rather than an integer (primary key). For example: ``` curl -X PATCH \ -H "Authorization: Token <TOKEN>" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://localhost:8000/api/dcim/devices/<pk>/ \ --data '{"cluster": 123}' ``` The following models and fields have been identified as affected by this bug: * Device: `cluster`, `primary_ip4`, `primary_ip6`, `virtual_chassis` * VirtualMachine: `primary_ip4`, `primary_ip6` ### Expected Behavior The device should be assigned to the specified cluster. ### Observed Behavior The request yields the following validation error: ``` { "cluster": { "non_field_errors": [ "Invalid data. Expected a dictionary, but got int." ] } } ```
adam added the type: bugstatus: accepted labels 2025-12-29 17:20:12 +01:00
adam closed this issue 2025-12-29 17:20:12 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1899