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

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

Closed
candlerb opened this issue Mar 16, 2023 · 1 comment · Fixed by #11992
Closed

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

candlerb opened this issue Mar 16, 2023 · 1 comment · Fixed by #11992
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@candlerb
Copy link
Contributor

candlerb commented Mar 16, 2023

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.

@candlerb candlerb added the type: bug A confirmed report of unexpected behavior in the application label Mar 16, 2023
@jeremystretch
Copy link
Member

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.

candlerb added a commit to candlerb/netbox that referenced this issue Mar 16, 2023
@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Mar 17, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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.

2 participants