go-netbox icon indicating copy to clipboard operation
go-netbox copied to clipboard

Creating Manufacture errors out because of missing required property devicetype_count

Open rogerscuall opened this issue 1 year ago • 9 comments

I'm trying to create a manufacturer like this:

man := n.NewManufacturerRequestWithDefaults()
man.Name = "somename"
man.Slug = "someslug"
resp, _, err := nb.DcimAPI.DcimManufacturersCreate(context.Background()).ManufacturerRequest(manu).Execute()

I get this error:

panic: failed to create manufacturer somename: no value given for required property devicetype_count

I can see how devicetype_count is required for a Manufacturer but not for a ManafacturerRequest. At the same time, the Manufacture is created, but the Execute returns an error.

rogerscuall avatar Jan 24 '24 19:01 rogerscuall

As the manufacturer is created, this is likely to be a deserialization error from the API response rather than a server error during the creation.

Could you mention what version Netbox you're using? Sadly, Netbox does not offer much in the way of API stability guarantees, and Netbox clients versions need to remain tightly coupled with the server version, otherwise this kind of error is likely to show up.

jqueuniet avatar Feb 01 '24 08:02 jqueuniet

Yes, 3.7.1 after it was created with goswagger. It also happens to generate DeviceType, DeviceRole, and Site. In line 107803 of the openapi.yaml file, devicetype_count is defined for the Manufacturer, and then, in 107814, is indeed ratified as required.

rogerscuall avatar Feb 01 '24 20:02 rogerscuall

Does devicetype_count need to be under AdditionalProperties or CustomFields? I tried both to no avail.

In my case, the API returns 201 and the manufacturer is still created in netbox, so I just bypass that error for now.

jacobsalmela avatar Feb 06 '24 13:02 jacobsalmela

I don't know. This is what I see:

Code

Code from openapi.yaml

    Manufacturer:
      type: object
      description: Adds support for custom fields and tags.
      properties:
        id:
          type: integer
          readOnly: true
        url:
          type: string
          format: uri
          readOnly: true
        display:
          type: string
          readOnly: true
        name:
          type: string
          maxLength: 100
        slug:
          type: string
          maxLength: 100
          pattern: ^[-a-zA-Z0-9_]+$
        description:
          type: string
          maxLength: 200
        tags:
          type: array
          items:
            $ref: '#/components/schemas/NestedTag'
        custom_fields:
          type: object
          additionalProperties: {}
        created:
          type: string
          format: date-time
          readOnly: true
          nullable: true
        last_updated:
          type: string
          format: date-time
          readOnly: true
          nullable: true
        devicetype_count:
          type: integer
          readOnly: true
        inventoryitem_count:
          type: integer
          readOnly: true
        platform_count:
          type: integer
          readOnly: true
      required:
      - created
      - devicetype_count
      - display
      - id
      - inventoryitem_count
      - last_updated
      - name
      - platform_count
      - slug
      - url
    ManufacturerRequest:
      type: object
      description: Adds support for custom fields and tags.
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 100
        slug:
          type: string
          minLength: 1
          maxLength: 100
          pattern: ^[-a-zA-Z0-9_]+$
        description:
          type: string
          maxLength: 200
        tags:
          type: array
          items:
            $ref: '#/components/schemas/NestedTagRequest'
        custom_fields:
          type: object
          additionalProperties: {}
      required:
      - name
      - slug

The Manufacturer requires devicetype_count, but the ManufacturerRequest does not. The same goes for DeviceType, DeviceRole, and Site and the Request counterpart. Yeah, I'm doing the same, ignoring the error for now. @jacobsalmela, you pointed out something I did not notice; I was so far ignoring the *http.Response from the Execute because it was contained inside the error, but as you said, it is returning 201. What may be related to @jqueuniet comment about the deserialization of API response is making up this error.

rogerscuall avatar Feb 07 '24 21:02 rogerscuall

I had some time to look into this issue this morning, and managed to reproduce it creating a device role with a Netbox 3.7.3 server and the current alpha release of the client (v3.7.1-alpha.0).

Reproduction code is as follows:

req := netbox.NewWritableDeviceRoleRequestWithDefaults()
req.SetName("test-role")
req.SetSlug("test-role")

result, resp, err := c.Netbox.
    DcimAPI.
    DcimDeviceRolesCreate(ctx).
    WritableDeviceRoleRequest(*req).
    Execute()

The error returned is no value given for required property device_count.

The list of broken endpoints this far is as follows:

  • dcim/manufacturers
  • dcim/device-roles
  • dcim/device-types
  • dcim/sites

I found a similar issue on the Netbox project for the tenancy/tenants endpoint, and mentioned the current status of this issue.

https://github.com/netbox-community/netbox/issues/14953

jqueuniet avatar Mar 08 '24 10:03 jqueuniet