Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jayGG83 opened this issue Oct 5, 2023 · 3 comments · Fixed by #14470
Closed

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

jayGG83 opened this issue Oct 5, 2023 · 3 comments · Fixed by #14470
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@jayGG83
Copy link

jayGG83 commented Oct 5, 2023

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.

@jayGG83 jayGG83 added the type: bug A confirmed report of unexpected behavior in the application label Oct 5, 2023
@jeremystretch
Copy link
Member

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 jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: medium Results in substantial degraded or broken functionality for specfic workflows labels Oct 5, 2023
@sleepinggenius2
Copy link
Contributor

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")'),
)

@arthanson
Copy link
Collaborator

arthanson commented 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 arthanson self-assigned this Nov 22, 2023
@arthanson arthanson removed the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Nov 22, 2023
@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Dec 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants