Selection Custom Field is created with incorrect choices type when choices is not set #6411

Closed
opened 2025-12-29 19:40:22 +01:00 by adam · 2 comments
Owner

Originally created by @axelfauvel on GitHub (Apr 27, 2022).

NetBox version

v3.2.1

Python version

3.9

Steps to Reproduce

Using pynetbox, I create a new custom field

nb.extras.custom_fields.create({"name": "zone", "content_types": ['dcim.rack'], "type": "select"})

When I try to access dcim/racks/ I get the following error

Server Error

There was a problem with your request. Please contact an administrator.

The complete exception is provided below:

<class 'TypeError'>

'NoneType' object is not iterable

Python version: 3.9.5
NetBox version: 3.2.1

If i edit the field and save i don't have the error anymore.

After querying the API, i found that there is a sligtly difference

Custom field created using API

{'id': 3, 'url': 'https://xxxx/api/extras/custom-fields/3/', 'display': 'Zone', 'content_types': ['dcim.rack'], 'type': 'select', 'object_type': None, 'data_type': 'string', 'name': 'zone', 'label': '', 'description': '', 'required': False, 'filter_logic': 'loose', 'default': None, 'weight': 100, 'validation_minimum': None, 'validation_maximum': None, 'validation_regex': '', 'choices': None, 'created': '2022-04-27T08:48:16.916995Z', 'last_updated': '2022-04-27T08:48:16.917018Z'}

Custom field created using UI

{'id': 3, 'url': 'https://xxxxapi/extras/custom-fields/3/', 'display': 'Zone', 'content_types': ['dcim.rack'], 'type': 'select', 'object_type': None, 'data_type': 'string', 'name': 'zone', 'label': '', 'description': '', 'required': False, 'filter_logic': 'loose', 'default': None, 'weight': 100, 'validation_minimum': None, 'validation_maximum': None, 'validation_regex': '', 'choices': [], 'created': '2022-04-27T08:48:16.916995Z', 'last_updated': '2022-04-27T08:50:41.211744Z'}

The choices field is set to None using API whereas it is set to [] using the UI

Expected Behavior

I should be able to access dcim/racks/

Observed Behavior

Server Error

There was a problem with your request. Please contact an administrator.

The complete exception is provided below:

<class 'TypeError'>

'NoneType' object is not iterable

Python version: 3.9.5
NetBox version: 3.2.1
Originally created by @axelfauvel on GitHub (Apr 27, 2022). ### NetBox version v3.2.1 ### Python version 3.9 ### Steps to Reproduce Using `pynetbox`, I create a new custom field ```python nb.extras.custom_fields.create({"name": "zone", "content_types": ['dcim.rack'], "type": "select"}) ``` When I try to access `dcim/racks/` I get the following error ``` Server Error There was a problem with your request. Please contact an administrator. The complete exception is provided below: <class 'TypeError'> 'NoneType' object is not iterable Python version: 3.9.5 NetBox version: 3.2.1 ``` If i edit the field and save i don't have the error anymore. After querying the API, i found that there is a sligtly difference ### Custom field created using API ```python {'id': 3, 'url': 'https://xxxx/api/extras/custom-fields/3/', 'display': 'Zone', 'content_types': ['dcim.rack'], 'type': 'select', 'object_type': None, 'data_type': 'string', 'name': 'zone', 'label': '', 'description': '', 'required': False, 'filter_logic': 'loose', 'default': None, 'weight': 100, 'validation_minimum': None, 'validation_maximum': None, 'validation_regex': '', 'choices': None, 'created': '2022-04-27T08:48:16.916995Z', 'last_updated': '2022-04-27T08:48:16.917018Z'} ``` ### Custom field created using UI ```python {'id': 3, 'url': 'https://xxxxapi/extras/custom-fields/3/', 'display': 'Zone', 'content_types': ['dcim.rack'], 'type': 'select', 'object_type': None, 'data_type': 'string', 'name': 'zone', 'label': '', 'description': '', 'required': False, 'filter_logic': 'loose', 'default': None, 'weight': 100, 'validation_minimum': None, 'validation_maximum': None, 'validation_regex': '', 'choices': [], 'created': '2022-04-27T08:48:16.916995Z', 'last_updated': '2022-04-27T08:50:41.211744Z'} ``` The `choices` field is set to `None` using API whereas it is set to `[]` using the UI ### Expected Behavior I should be able to access `dcim/racks/` ### Observed Behavior ``` Server Error There was a problem with your request. Please contact an administrator. The complete exception is provided below: <class 'TypeError'> 'NoneType' object is not iterable Python version: 3.9.5 NetBox version: 3.2.1 ```
adam added the type: bugstatus: revisions needed labels 2025-12-29 19:40:22 +01:00
adam closed this issue 2025-12-29 19:40:22 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 27, 2022):

Using pynetbox, I create a new custom field

Per the bug report instructions:

If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox.

Please update your post above to include reproduction steps using raw REST API queries, or equivalent steps performed using the NetBox UI.

@jeremystretch commented on GitHub (Apr 27, 2022): > Using pynetbox, I create a new custom field Per the bug report instructions: > If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. Please update your post above to include reproduction steps using raw REST API queries, or equivalent steps performed using the NetBox UI.
Author
Owner

@axelfauvel commented on GitHub (May 3, 2022):

Hi @jeremystretch

I have just tried to reproduce using raw API and i don't have the bug.

Sorry for the inconvenience, i will open a bug on pynetbox repository.

@axelfauvel commented on GitHub (May 3, 2022): Hi @jeremystretch I have just tried to reproduce using raw API and i don't have the bug. Sorry for the inconvenience, i will open a bug on pynetbox repository.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6411