netbox-community / pynetbox

Python API client library for Netbox.
Apache License 2.0
543 stars 167 forks source link

Weight Import Bug #534

Closed danner26 closed 1 year ago

danner26 commented 1 year ago

I believe there might be a bug within pynetbox. When doing an import with a device that has the weight object defined, specifically with 2 decimal places, I keep experiencing the following error: {"weight":["A valid number is required."]}. I currently hold the belief that this error is directly related to either be a pynetbox issue or an upstream NetBox issue, but I am leaning towards pynetbox. I have already verified that the Weight model in NetBox is a DecimalField (with decimal_places=2).

I haven't confirmed or denied this, but @jsenecal and I tackled a seemingly similar issue in the devicetype-library when validating weight objects. You can reference this PR for more information but essentially we needed to add parse_float=decimal.Decimal to our json.loads() statement and create a custom loader (i.e. Loader=DecimalSafeLoader - see tests/yaml_loader.py in the devicetype-library for reference).

Here is some sample JSON of the data we are passing into the pynetbox dcim.device_types.create() function (the YAML can be found here): {'manufacturer': {'name': 'Datto', 'slug': 'datto'}, 'model': 'AP440', 'slug': 'datto-ap440', 'part_number': 'AP440', 'u_height': 0, 'is_full_depth': False, 'comments': '[Datto Access Points](https://www.datto.com/product-assets/wifi/AP840_840E_Datasheet_US.pdf)', 'weight': [{'value': 1.19, 'unit': 'lb'}], 'power-ports': [{'name': 'DC', 'type': 'dc-terminal', 'maximum_draw': 26}], 'interfaces': [{'name': 'Port 1', 'type': '1000base-t'}, {'name': 'Port 2', 'type': '1000base-t', 'poe_mode': 'pd', 'poe_type': 'type2-ieee802.3at'}, {'name': 'WiFi', 'type': 'ieee802.11ax'}]}

Please let me know if I can assist in any way or provide anymore information

danner26 commented 1 year ago

We actually figure this issue out, so this can be ignored See this discussion if you need more information