Custom Field Choice Set Bulk Import error "Nested arrays must have same length" #8720

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

Originally created by @jayGG83 on GitHub (Oct 5, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.6.3

Python version

3.10

Steps to Reproduce

  1. Select Custom Field Choices import
  2. Data to import:

CSV:

name;description;extra_choices
numbers;Numbers;7,13,18,23,26,32,38,80

JSON:

{
    "name": "numbers",
    "description": "Numbers",
    "extra_choices": [7,13,18,23,26,32,38,80]
}

YAML:

---
name: numbers
description: Numbers
extra_choices: 7,13,18,23,26,32,38,80
  1. Click Submit

Expected Behavior

It is expected to create the cusotm field choices

Observed Behavior

Returns this error in all cases: Record 1 extra_choices: Nested arrays must have the same length.

Originally created by @jayGG83 on GitHub (Oct 5, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.6.3 ### Python version 3.10 ### Steps to Reproduce 1. Select Custom Field Choices import 2. Data to import: CSV: ``` name;description;extra_choices numbers;Numbers;7,13,18,23,26,32,38,80 ``` JSON: ``` { "name": "numbers", "description": "Numbers", "extra_choices": [7,13,18,23,26,32,38,80] } ``` YAML: ``` --- name: numbers description: Numbers extra_choices: 7,13,18,23,26,32,38,80 ``` 3. Click Submit ### Expected Behavior It is expected to create the cusotm field choices ### Observed Behavior Returns this error in all cases: Record 1 extra_choices: Nested arrays must have the same length.
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:40:21 +01:00
adam closed this issue 2025-12-29 20:40:21 +01:00
Author
Owner

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

The root issue here is that each choice value is being interpreted as an array, such that e.g. 13 becomes ["1", "3"]. The error message is a bit of a red herring, and presents only if all the choice values are not of the same length. For example, importing a field value of A1,B2,C3 will result in choices [(A, 1), (B, 2), (C, 3)].

I'm not sure we have a great option for handling nested arrays in CSV data, but we should seek to support them when expressed via JSON/YAML.

@jeremystretch commented on GitHub (Oct 5, 2023): The root issue here is that each choice value is being interpreted as an array, such that e.g. `13` becomes `["1", "3"]`. The error message is a bit of a red herring, and presents only if all the choice values are not of the same length. For example, importing a field value of `A1,B2,C3` will result in choices `[(A, 1), (B, 2), (C, 3)]`. I'm not sure we have a great option for handling nested arrays in CSV data, but we should seek to support them when expressed via JSON/YAML.
Author
Owner

@sleepinggenius2 commented on GitHub (Oct 5, 2023):

I ran into a similar requirement recently in a plugin I was working on and defining the field like below on the *ImportForm class has worked great for CSV data. Admittedly, I have not tried importing JSON or YAML.

field = SimpleArrayField(
    base_field=SimpleArrayField(
        base_field=CharField(),
        min_length=2,
        max_length=2,
    ),
    delimiter=';',
    required=False,
    help_text=_('Semicolon-separated list of comma-separated pairs, encased with double quotes (e.g. "value1,Label 1;value2,Label 2")'),
)
@sleepinggenius2 commented on GitHub (Oct 5, 2023): I ran into a similar requirement recently in a plugin I was working on and defining the field like below on the `*ImportForm` class has worked great for CSV data. Admittedly, I have not tried importing JSON or YAML. ```python field = SimpleArrayField( base_field=SimpleArrayField( base_field=CharField(), min_length=2, max_length=2, ), delimiter=';', required=False, help_text=_('Semicolon-separated list of comma-separated pairs, encased with double quotes (e.g. "value1,Label 1;value2,Label 2")'), ) ```
Author
Owner

@arthanson commented on GitHub (Oct 13, 2023):

Actually just using a comma-separated string for nested items works. in the example given, changing it to the following should work:

name;description;extra_choices
numbers;Numbers;"7,13,18,23,26,32,38,80"
@arthanson commented on GitHub (Oct 13, 2023): Actually just using a comma-separated string for nested items works. in the example given, changing it to the following should work: ``` name;description;extra_choices numbers;Numbers;"7,13,18,23,26,32,38,80" ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8720