CSV validation: column headings foo.bar and foo.baz cause column to go missing #7762

Closed
opened 2025-12-29 20:27:55 +01:00 by adam · 1 comment
Owner

Originally created by @candlerb on GitHub (Mar 16, 2023).

Originally assigned to: @candlerb on GitHub.

NetBox version

v3.4.6

Python version

3.8

Steps to Reproduce

Go to /ipam/ip-addresses/import/ (IPAM > IP Addresses > upload)

Paste in the following data into the text area:

address,status,virtual_machine.site,virtual_machine.name,interface
192.168.1.1/30,active,SITE_A,Server_1,Net1

Click Submit.

(Example taken from discussion #11988)

Expected Behavior

Successful upload, or a meaningful error response.

Observed Behavior

The data is rejected with the following error:

Row 1: Expected 4 columns but found 5

The error message suggests that the submitter only included four column headings, which is incorrect.

Analysis

Ref: Discussion link.

Looking at test cases for CSV upload, I see this example:

        input = """
        address,status,vrf.name
...
        output = (
            {'address': None, 'status': None, 'vrf': 'name'},
                                              ^^^^^^^^^^^^^

I am guessing that if there's a column "foo.bar" and another column "foo.baz", the second column overwrites the dict key "foo" in this structure.

Resolution

The simplest resolution would be to detect duplicate/overlapping column names, and report them as such. (e.g. "Column 'foo.baz' conflicts with column 'foo.bar'")

This would also capture the simpler case:

address,status,status
192.168.1.1/30,active,active

(also wrongly reported as "Expected 2 columns but found 3")

A longer-term resolution would be to support the use case which the original poster wanted, which was to be able to refer to a related object via more than one attribute, as had been originally proposed here when CSV upload was reworked for v2.8.2. I think that would be a substantial change.

Originally created by @candlerb on GitHub (Mar 16, 2023). Originally assigned to: @candlerb on GitHub. ### NetBox version v3.4.6 ### Python version 3.8 ### Steps to Reproduce Go to `/ipam/ip-addresses/import/` (IPAM > IP Addresses > upload) Paste in the following data into the text area: ``` address,status,virtual_machine.site,virtual_machine.name,interface 192.168.1.1/30,active,SITE_A,Server_1,Net1 ``` Click Submit. (Example taken from discussion #11988) ### Expected Behavior Successful upload, or a meaningful error response. ### Observed Behavior The data is rejected with the following error: ``` Row 1: Expected 4 columns but found 5 ``` The error message suggests that the submitter only included four column headings, which is incorrect. ## Analysis Ref: [Discussion link](https://github.com/netbox-community/netbox/discussions/11988#discussioncomment-5331838). Looking at test cases for CSV upload, I see [this example](https://github.com/netbox-community/netbox/blob/v3.4.6/netbox/utilities/tests/test_forms.py#L323-L330): ``` input = """ address,status,vrf.name ... output = ( {'address': None, 'status': None, 'vrf': 'name'}, ^^^^^^^^^^^^^ ``` I am guessing that if there's a column "foo.bar" and another column "foo.baz", the second column overwrites the dict key "foo" in this structure. ## Resolution The simplest resolution would be to detect duplicate/overlapping column names, and report them as such. (e.g. _"Column 'foo.baz' conflicts with column 'foo.bar'"_) This would also capture the simpler case: ``` address,status,status 192.168.1.1/30,active,active ``` (also wrongly reported as "Expected 2 columns but found 3") A longer-term resolution would be to support the use case which the original poster wanted, which was to be able to refer to a related object via more than one attribute, as had been originally proposed [here](https://github.com/netbox-community/netbox/issues/3147#issuecomment-565473082) when CSV upload was reworked for v2.8.2. I think that would be a substantial change.
adam added the type: bugstatus: accepted labels 2025-12-29 20:27:55 +01:00
adam closed this issue 2025-12-29 20:27:56 +01:00
Author
Owner

@jeremystretch commented on GitHub (Mar 16, 2023):

The error message is expected: CSV import currently supports only one declaration of each column. However if you or @kevintedder would like to resubmit this as a feature request we can explore the use case and potential implementations to support specifying multiple attributes per field.

@jeremystretch commented on GitHub (Mar 16, 2023): The error message is expected: CSV import currently supports only one declaration of each column. However if you or @kevintedder would like to resubmit this as a feature request we can explore the use case and potential implementations to support specifying multiple attributes per field.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7762