Importing device type yaml results in type error #8375

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

Originally created by @DanSheps on GitHub (Jul 27, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.5.6

Python version

3.9

Steps to Reproduce

  1. Create a manufacturer named Juniper
  2. Import the following data (copied from the Juniper MX204 definition in the device type library)
---
---
manufacturer: Juniper
model: MX204
slug: juniper-mx204
interfaces:
  - name: fxp0
    type: 1000base-t
    mgmt_only: true
  - name: et-0/0/0
    type: 100gbase-x-qsfp28
  - name: et-0/0/1
    type: 100gbase-x-qsfp28
  - name: et-0/0/2
    type: 100gbase-x-qsfp28
  - name: et-0/0/3
    type: 100gbase-x-qsfp28
  - name: xe-0/1/0
    type: 10gbase-x-sfpp
  - name: xe-0/1/1
    type: 10gbase-x-sfpp
  - name: xe-0/1/2
    type: 10gbase-x-sfpp
  - name: xe-0/1/3
    type: 10gbase-x-sfpp
  - name: xe-0/1/4
    type: 10gbase-x-sfpp
  - name: xe-0/1/5
    type: 10gbase-x-sfpp
  - name: xe-0/1/6
    type: 10gbase-x-sfpp
  - name: xe-0/1/7
    type: 10gbase-x-sfpp
power-ports:
  - name: PSU0
    type: iec-60320-c14
    maximum_draw: 650
  - name: PSU1
    type: iec-60320-c14
    maximum_draw: 650
console-ports:
  - name: Console
    type: rj-45

Expected Behavior

Import succeeds

Observed Behavior


unsupported operand type(s) for %: 'float' and 'decimal.Decimal'
Originally created by @DanSheps on GitHub (Jul 27, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.5.6 ### Python version 3.9 ### Steps to Reproduce 1. Create a manufacturer named Juniper 2. Import the following data (copied from the [Juniper MX204](https://github.com/netbox-community/devicetype-library/blob/master/device-types/Juniper/MX204.yaml) definition in the device type library) ``` --- --- manufacturer: Juniper model: MX204 slug: juniper-mx204 interfaces: - name: fxp0 type: 1000base-t mgmt_only: true - name: et-0/0/0 type: 100gbase-x-qsfp28 - name: et-0/0/1 type: 100gbase-x-qsfp28 - name: et-0/0/2 type: 100gbase-x-qsfp28 - name: et-0/0/3 type: 100gbase-x-qsfp28 - name: xe-0/1/0 type: 10gbase-x-sfpp - name: xe-0/1/1 type: 10gbase-x-sfpp - name: xe-0/1/2 type: 10gbase-x-sfpp - name: xe-0/1/3 type: 10gbase-x-sfpp - name: xe-0/1/4 type: 10gbase-x-sfpp - name: xe-0/1/5 type: 10gbase-x-sfpp - name: xe-0/1/6 type: 10gbase-x-sfpp - name: xe-0/1/7 type: 10gbase-x-sfpp power-ports: - name: PSU0 type: iec-60320-c14 maximum_draw: 650 - name: PSU1 type: iec-60320-c14 maximum_draw: 650 console-ports: - name: Console type: rj-45 ``` ### Expected Behavior Import succeeds ### Observed Behavior ```<class 'TypeError'> unsupported operand type(s) for %: 'float' and 'decimal.Decimal' ```
adam added the type: bugstatus: accepted labels 2025-12-29 20:35:55 +01:00
adam closed this issue 2025-12-29 20:35:56 +01:00
Author
Owner

@DanSheps commented on GitHub (Jul 27, 2023):

Sentry BR:

Exception
TypeError: unsupported operand type(s) for %: 'float' and 'decimal.Decimal'
(10 additional frame(s) were not displayed)
...
  File "utilities/views.py", line 99, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "netbox/views/generic/bulk_views.py", line 449, in post
    new_objs = self.create_and_update_objects(form, request)
  File "netbox/views/generic/bulk_views.py", line 407, in create_and_update_objects
    if model_form.is_valid():
  File "utilities/forms/mixins.py", line 52, in is_valid
    is_valid = super().is_valid()
  File "dcim/models/devices.py", line 235, in clean
    if self.u_height % decimal.Decimal(0.5):
@DanSheps commented on GitHub (Jul 27, 2023): Sentry BR: ``` Exception TypeError: unsupported operand type(s) for %: 'float' and 'decimal.Decimal' (10 additional frame(s) were not displayed) ... File "utilities/views.py", line 99, in dispatch return super().dispatch(request, *args, **kwargs) File "netbox/views/generic/bulk_views.py", line 449, in post new_objs = self.create_and_update_objects(form, request) File "netbox/views/generic/bulk_views.py", line 407, in create_and_update_objects if model_form.is_valid(): File "utilities/forms/mixins.py", line 52, in is_valid is_valid = super().is_valid() File "dcim/models/devices.py", line 235, in clean if self.u_height % decimal.Decimal(0.5): ```
Author
Owner

@DanSheps commented on GitHub (Jul 27, 2023):

It looks like this was added before we added "U's" to the device type library as mandatory, however we should be trying to catch missing fields more gracefully (and perhaps with a better error).

@DanSheps commented on GitHub (Jul 27, 2023): It looks like this was added before we added "U's" to the device type library as mandatory, however we should be trying to catch missing fields more gracefully (and perhaps with a better error).
Author
Owner

@leseras commented on GitHub (Jul 28, 2023):

I have been experiencing this issue repeatedly this morning with several different files from the device-library.

From MikroTik:
RB260GSP.yaml
RB260GS.yaml
RB750Gr3.yaml
RB750r3.yaml

Does seem to have something to do with the unit_height:

Internal Server Error: /dcim/device-types/import/
Traceback (most recent call last):
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner
    response = get_response(request)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/generic/base.py", line 77, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/netbox/utilities/views.py", line 99, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 142, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/netbox/netbox/netbox/views/generic/bulk_views.py", line 442, in post
    new_objs = self.create_and_update_objects(form, request)
  File "/opt/netbox/netbox/netbox/views/generic/bulk_views.py", line 400, in create_and_update_objects
    if model_form.is_valid():
  File "/opt/netbox/netbox/utilities/forms/forms.py", line 69, in is_valid
    is_valid = super().is_valid()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/forms/forms.py", line 205, in is_valid
    return self.is_bound and not self.errors
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/forms/forms.py", line 200, in errors
    self.full_clean()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/forms/forms.py", line 439, in full_clean
    self._post_clean()
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/forms/models.py", line 492, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1455, in full_clean
    self.clean()
  File "/opt/netbox/netbox/dcim/models/devices.py", line 220, in clean
    if self.u_height % decimal.Decimal(0.5):

Fast Solution to avoid error: Just add u_height: <0 or 1> to the specs

@leseras commented on GitHub (Jul 28, 2023): I have been experiencing this issue repeatedly this morning with several different files from the device-library. From MikroTik: RB260GSP.yaml RB260GS.yaml RB750Gr3.yaml RB750r3.yaml Does seem to have something to do with the unit_height: ``` Internal Server Error: /dcim/device-types/import/ Traceback (most recent call last): File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 56, in inner response = get_response(request) File "/opt/netbox/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view return self.dispatch(request, *args, **kwargs) File "/opt/netbox/netbox/netbox/views/generic/base.py", line 77, in dispatch return super().dispatch(request, *args, **kwargs) File "/opt/netbox/netbox/utilities/views.py", line 99, in dispatch return super().dispatch(request, *args, **kwargs) File "/opt/netbox/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 142, in dispatch return handler(request, *args, **kwargs) File "/opt/netbox/netbox/netbox/views/generic/bulk_views.py", line 442, in post new_objs = self.create_and_update_objects(form, request) File "/opt/netbox/netbox/netbox/views/generic/bulk_views.py", line 400, in create_and_update_objects if model_form.is_valid(): File "/opt/netbox/netbox/utilities/forms/forms.py", line 69, in is_valid is_valid = super().is_valid() File "/opt/netbox/venv/lib/python3.10/site-packages/django/forms/forms.py", line 205, in is_valid return self.is_bound and not self.errors File "/opt/netbox/venv/lib/python3.10/site-packages/django/forms/forms.py", line 200, in errors self.full_clean() File "/opt/netbox/venv/lib/python3.10/site-packages/django/forms/forms.py", line 439, in full_clean self._post_clean() File "/opt/netbox/venv/lib/python3.10/site-packages/django/forms/models.py", line 492, in _post_clean self.instance.full_clean(exclude=exclude, validate_unique=False) File "/opt/netbox/venv/lib/python3.10/site-packages/django/db/models/base.py", line 1455, in full_clean self.clean() File "/opt/netbox/netbox/dcim/models/devices.py", line 220, in clean if self.u_height % decimal.Decimal(0.5): ``` **Fast Solution to avoid error:** Just add `u_height: <0 or 1>` to the specs
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8375