API device has different behaviour on response #8394

Closed
opened 2025-12-29 20:36:09 +01:00 by adam · 3 comments
Owner

Originally created by @lchabert on GitHub (Jul 31, 2023).

NetBox version

v3.5.6

Python version

3.10

Steps to Reproduce

  1. Import device-type to check behaviour
curl -X 'POST' \
  'http://10.204.5.36:8000/api/dcim/device-types/' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'X-CSRFTOKEN: XXXXXX' \
  -d '[{
    "id": null,
    "manufacturer": {
        "name": "Patton"
    },
    "model": "PATTONMODEL",
    "slug": "PATTONMODEL",
    "description": "MyDescription",
    "u_height": 1
},
{
    "id": null,
    "manufacturer": {
        "name": "ErrorManuf"
    },
    "model": "VGWTESTMODEL",
    "slug": "VGWTESTMODEL",
    "description": "MyDescription 2,
    "u_height": 1
}]'
 => Response
[
  {},
  {
    "manufacturer": [
      "Related object not found using the provided attributes: {'name': 'TestMan'}"
    ]
  }
]
  1. Create two devices with one error
curl -X 'POST' \
  'http://10.204.5.36:8000/api/dcim/devices/' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'X-CSRFTOKEN: XXXX' \
  -d '    [{
        "id": null,
        "name": "valid.device",
        "site": {
            "name": "MARSEILLE"
        },
        "device_type": {
            "model": "NLBA101AX-1030-ADC"
        },
        "device_role": {
            "name": "Load Balancer"
        },
        "tenant": {
            "slug": "jn"
        }
    },
    {
        "id": null,
        "name": "error.device",
        "site": {
            "name": "MARSEILLE"
        },
        "device_type": {
            "model": ""
        },
        "device_role": {
            "name": "Load Balancer"
        },
        "tenant": {
            "slug": "jn"
        }
    }]'

 => Response
{
  "device_type": [
    "Related object not found using the provided attributes: {'model': ''}"
  ]
}

Expected Behavior

The reponse should be the same as the other types when bulk insert

[
  {},
  {
    "device_type": [
    "Related object not found using the provided attributes: {'model': ''}"
  ]
  }
]

Observed Behavior

A raw error was return instead the the list of errors, one per device.

Originally created by @lchabert on GitHub (Jul 31, 2023). ### NetBox version v3.5.6 ### Python version 3.10 ### Steps to Reproduce 1. Import device-type to check behaviour ``` curl -X 'POST' \ 'http://10.204.5.36:8000/api/dcim/device-types/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'X-CSRFTOKEN: XXXXXX' \ -d '[{ "id": null, "manufacturer": { "name": "Patton" }, "model": "PATTONMODEL", "slug": "PATTONMODEL", "description": "MyDescription", "u_height": 1 }, { "id": null, "manufacturer": { "name": "ErrorManuf" }, "model": "VGWTESTMODEL", "slug": "VGWTESTMODEL", "description": "MyDescription 2, "u_height": 1 }]' => Response [ {}, { "manufacturer": [ "Related object not found using the provided attributes: {'name': 'TestMan'}" ] } ] ``` 2. Create two devices with one error ``` curl -X 'POST' \ 'http://10.204.5.36:8000/api/dcim/devices/' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'X-CSRFTOKEN: XXXX' \ -d ' [{ "id": null, "name": "valid.device", "site": { "name": "MARSEILLE" }, "device_type": { "model": "NLBA101AX-1030-ADC" }, "device_role": { "name": "Load Balancer" }, "tenant": { "slug": "jn" } }, { "id": null, "name": "error.device", "site": { "name": "MARSEILLE" }, "device_type": { "model": "" }, "device_role": { "name": "Load Balancer" }, "tenant": { "slug": "jn" } }]' => Response { "device_type": [ "Related object not found using the provided attributes: {'model': ''}" ] } ``` ### Expected Behavior The reponse should be the same as the other types when bulk insert ``` [ {}, { "device_type": [ "Related object not found using the provided attributes: {'model': ''}" ] } ] ``` ### Observed Behavior A raw error was return instead the the list of errors, one per device.
adam closed this issue 2025-12-29 20:36:09 +01:00
Author
Owner

@commonism commented on GitHub (Aug 3, 2023):

The API Specification does not even allow posting multiple devices, array is not specified as argument or return value.


  /api/dcim/devices/:
    post:
      operationId: dcim_devices_create
      description: Post a list of device objects.
      tags:
      - dcim
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WritableDeviceWithConfigContextRequest'
        required: true


    WritableDeviceWithConfigContextRequest:
      type: object
      description: Adds support for custom fields and tags.
      properties:
        name:
          type: string
          nullable: true
          maxLength: 64

@commonism commented on GitHub (Aug 3, 2023): The API Specification does not even allow posting multiple devices, array is not specified as argument or return value. ```yaml … /api/dcim/devices/: post: operationId: dcim_devices_create description: Post a list of device objects. tags: - dcim requestBody: content: application/json: schema: $ref: '#/components/schemas/WritableDeviceWithConfigContextRequest' required: true … ``` ```yaml … WritableDeviceWithConfigContextRequest: type: object description: Adds support for custom fields and tags. properties: name: type: string nullable: true maxLength: 64 … ```
Author
Owner

@github-actions[bot] commented on GitHub (Dec 18, 2023):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Dec 18, 2023): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Jan 18, 2024):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Jan 18, 2024): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8394