TypeError when resolving custom field choice set with a not "required" multiselect #8573

Closed
opened 2025-12-29 20:38:19 +01:00 by adam · 7 comments
Owner

Originally created by @DanSheps on GitHub (Sep 5, 2023).

Originally assigned to: @DanSheps on GitHub.

NetBox version

v3.6.0

Python version

3.9

Steps to Reproduce

  1. Have a multi selection custom field from a previous version of NetBox that is not "required" and the default value being "Network Staff" (not "null")
    a) Name: Allowed Access
    b) Choice Set: "Network Staff", "Server Staff"
    c) Connected to Device Type
  2. Upgrade to 3.6
  3. Add a Device Type

Note: Reproducable from scratch as well after some other issues have been resolved with custom fields

Expected Behavior

The add Device Type form should appear

Observed Behavior

TypeError: 'in ' requires string as left operand, not NoneType

Originally created by @DanSheps on GitHub (Sep 5, 2023). Originally assigned to: @DanSheps on GitHub. ### NetBox version v3.6.0 ### Python version 3.9 ### Steps to Reproduce 1. Have a multi selection custom field from a previous version of NetBox that is not "required" and the default value being "Network Staff" (not "null") a) Name: Allowed Access b) Choice Set: "Network Staff", "Server Staff" c) Connected to Device Type 2. Upgrade to 3.6 3. Add a Device Type Note: Reproducable from scratch as well after some other issues have been resolved with custom fields ### Expected Behavior The add Device Type form should appear ### Observed Behavior TypeError: 'in <string>' requires string as left operand, not NoneType
adam added the type: bug label 2025-12-29 20:38:19 +01:00
adam closed this issue 2025-12-29 20:38:19 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 5, 2023):

I'm not able to reproduce this following these steps:

  1. Install NetBox v3.5.9
  2. Create a custom field with the following attributes:
  • Content types: Device type
  • Name: allowed_access
  • Type: Multi-select
  • Required: False
  • Default value: ["Network Staff"]
  • Choices: Network Staff,Server Staff
  1. Upgrade to NetBox v3.6.0
  2. Create a new device type

The new device type is created successfully, with its allowed_access custom field set to "Network Staff."

@jeremystretch commented on GitHub (Sep 5, 2023): I'm not able to reproduce this following these steps: 1. Install NetBox v3.5.9 2. Create a custom field with the following attributes: - Content types: Device type - Name: `allowed_access` - Type: Multi-select - Required: False - Default value: `["Network Staff"]` - Choices: `Network Staff,Server Staff` 3. Upgrade to NetBox v3.6.0 4. Create a new device type The new device type is created successfully, with its `allowed_access` custom field set to "Network Staff."
Author
Owner

@DanSheps commented on GitHub (Sep 5, 2023):

Yes, diving into it a little more it may have been partially a pre-2.10 issue that got carried over. At that time, the default was stored as a varying char and the default value was "Network Staff" and not ["Network Staff"]. It looks like at the time, SELECT/MULTISELECT wasn't taken into account and the default was carried over as a string.

It seems to be a very specific set of circumstances and it took most of the day to get to this:

  • Start with v2.9.11
  • Create a custom field:
    • Object: dcim > device type
    • Name: department
    • Choices: network, server, admin, business
    • Default: "" (empty field)
  • Upgrade to 2.11.12
  • Change customfield:
    • Type: multiselect
  • Upgrade to 3.0.0
  • Upgrade to 3.5.9
  • Upgrade to 3.6.0
  • Try to create a device type

You will notice, if you go edit the custom field, that the custom field is a string and not an array with a string for the choice.

I am going to change the severity to low, and I think the better route is to add a migration to check for a string in the jsonb and if the type is an multi-select object

@DanSheps commented on GitHub (Sep 5, 2023): Yes, diving into it a little more it may have been partially a pre-2.10 issue that got carried over. At that time, the default was stored as a varying char and the default value was `"Network Staff"` and not `["Network Staff"]`. It looks like at the time, SELECT/MULTISELECT wasn't taken into account and the default was carried over as a string. It seems to be a very specific set of circumstances and it took most of the day to get to this: * Start with v2.9.11 * Create a custom field: * Object: dcim > device type * Name: department * Choices: network, server, admin, business * Default: "" (empty field) * Upgrade to 2.11.12 * Change customfield: * Type: multiselect * Upgrade to 3.0.0 * Upgrade to 3.5.9 * Upgrade to 3.6.0 * Try to create a device type You will notice, if you go edit the custom field, that the custom field is a string and not an array with a string for the choice. I am going to change the severity to low, and I think the better route is to add a migration to check for a string in the jsonb and if the type is an multi-select object
Author
Owner

@DanSheps commented on GitHub (Sep 6, 2023):

Converted the PR to a draft and we can discuss whehther this is an important item to even take into account.

It looks like it was a combination of:

  1. Bad data that persisted from 2.9.11 to 2.11.12 up to 3.5.9 and then finally 3.6.0. It was never found because the check in validate() for the default ignores data that is blank. You can save "" right now in 3.6.0 so the change in 2.11.12 would have not been caught.
  2. Data was never updated to trigger a validation check.

I am okay with skipping on this, but I do think we should:

  1. Proceed with this fix (in the PR) or insert a migration to properly migrate string defaults in custom fields that are part of a multi-select to an array
  2. Add a check for a this condition (blank default on a multi-select)
@DanSheps commented on GitHub (Sep 6, 2023): Converted the PR to a draft and we can discuss whehther this is an important item to even take into account. It looks like it was a combination of: 1. Bad data that persisted from 2.9.11 to 2.11.12 up to 3.5.9 and then finally 3.6.0. It was never found because the check in validate() for the default ignores data that is blank. You can save "" right now in 3.6.0 so the change in 2.11.12 would have not been caught. 2. Data was never updated to trigger a validation check. I am okay with skipping on this, but I do think we should: 1. Proceed with this fix (in the PR) or insert a migration to properly migrate string defaults in custom fields that are part of a multi-select to an array 2. Add a check for a this condition (blank default on a multi-select)
Author
Owner

@github-actions[bot] commented on GitHub (Dec 5, 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 5, 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

@DanSheps commented on GitHub (Dec 5, 2023):

I came across this again in a slightly different manner. I think I have a way to reproduce this consistently.

@DanSheps commented on GitHub (Dec 5, 2023): I came across this again in a slightly different manner. I think I have a way to reproduce this consistently.
Author
Owner

@jeremystretch commented on GitHub (Dec 27, 2023):

@DanSheps have you made any progress on this?

@jeremystretch commented on GitHub (Dec 27, 2023): @DanSheps have you made any progress on this?
Author
Owner

@DanSheps commented on GitHub (Dec 28, 2023):

Looking into this, I think this all has to do with old (not nessicarily bad) data from previous upgrades over the years.

I cannot reproduce this on a clean instance because of the way the UI has changed and you can no longer do things (such as change a select to a mutliselect) in the UI that was possible previously.

I would say it is best to close this out for now and if I run into it again I will try and get some more information when it happened. I stupidly did not save the traceback and it wasn't captured in sentry.

@DanSheps commented on GitHub (Dec 28, 2023): Looking into this, I think this all has to do with old (not nessicarily bad) data from previous upgrades over the years. I cannot reproduce this on a clean instance because of the way the UI has changed and you can no longer do things (such as change a select to a mutliselect) in the UI that was possible previously. I would say it is best to close this out for now and if I run into it again I will try and get some more information when it happened. I stupidly did not save the traceback and it wasn't captured in sentry.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8573