Validate all headers/fields when bulk import objects #7578

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

Originally created by @julianstolp on GitHub (Jan 30, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.4.3

Python version

3.8

Steps to Reproduce

  1. Open Prefix Bulk Import
  2. Specify all required field options and add some dummy data
    prefix,status,testa,testb
    10.10.10.0/24,active,a,b
  3. Press Import
  4. Import is done without any complains

Expected Behavior

Fields which are not stated in Field Options should throw an error, or a warning that some data was ignored.

Observed Behavior

Import is done without any complains, Looks like all data was imported correct, although some fields were ignored

Originally created by @julianstolp on GitHub (Jan 30, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.4.3 ### Python version 3.8 ### Steps to Reproduce 1. Open Prefix Bulk Import 2. Specify all required field options and add some dummy data `prefix,status,testa,testb` `10.10.10.0/24,active,a,b` 4. Press Import 5. Import is done without any complains ### Expected Behavior Fields which are not stated in Field Options should throw an error, or a warning that some data was ignored. ### Observed Behavior Import is done without any complains, Looks like all data was imported correct, although some fields were ignored
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 20:25:38 +01:00
adam closed this issue 2025-12-29 20:25:38 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Feb 8, 2023):

It this a regression? Did it used to throw an error? Are we sure this is actually wanted behavior before I look into this?

@kkthxbye-code commented on GitHub (Feb 8, 2023): It this a regression? Did it used to throw an error? Are we sure this is actually wanted behavior before I look into this?
Author
Owner

@julianstolp commented on GitHub (Feb 8, 2023):

I just tried it in v3.09. It raises a Unexpected column header "testa" found. error.

@julianstolp commented on GitHub (Feb 8, 2023): I just tried it in v3.09. It raises a `Unexpected column header "testa" found.` error.
Author
Owner

@julianstolp commented on GitHub (Feb 8, 2023):

Also checked versions 3.2.0, 3.3.0 and 3.4.0. The import works with version 3.4.0, before raises an Unexpected column header "testa" found. error.

@julianstolp commented on GitHub (Feb 8, 2023): Also checked versions 3.2.0, 3.3.0 and 3.4.0. The import works with version 3.4.0, before raises an `Unexpected column header "testa" found.` error.
Author
Owner

@kkthxbye-code commented on GitHub (Feb 8, 2023):

@arthanson - Can you take a look at this as it's part of the bulk import stuff you changed.

I tried just adding the following validation on L147 here:

56c7a238a4/netbox/utilities/forms/forms.py (L134-L153)

for header in headers.keys():
    if header not in self.fields:
        raise forms.ValidationError(f'Unexpected column header "{header}" found.')

But the ValidationError is caught here and discarded:

56c7a238a4/netbox/netbox/views/generic/bulk_views.py (L461-L462)

@kkthxbye-code commented on GitHub (Feb 8, 2023): @arthanson - Can you take a look at this as it's part of the bulk import stuff you changed. I tried just adding the following validation on L147 here: https://github.com/netbox-community/netbox/blob/56c7a238a4905d3220b63d8b33b07ca52df7efd1/netbox/utilities/forms/forms.py#L134-L153 ```python for header in headers.keys(): if header not in self.fields: raise forms.ValidationError(f'Unexpected column header "{header}" found.') ``` But the ValidationError is caught here and discarded: https://github.com/netbox-community/netbox/blob/56c7a238a4905d3220b63d8b33b07ca52df7efd1/netbox/netbox/views/generic/bulk_views.py#L461-L462
Author
Owner

@jeremystretch commented on GitHub (Apr 10, 2023):

We should consider JSON/YAML imports as well as CSV. If we're concerned about checking for extraneous CSV headers (and IMO we should be), then this functionality should exist for JSON- and YAML-formatted data as well. Unlike CSV, which specifies a single row of headers, the fields for each object expressed in JSON or YAML can vary with each object, so each object will need to be validated individually. I think it's reasonable to replicate this pattern for CSV data, even if it's not technically necessary.

@jeremystretch commented on GitHub (Apr 10, 2023): We should consider JSON/YAML imports as well as CSV. If we're concerned about checking for extraneous CSV headers (and IMO we should be), then this functionality should exist for JSON- and YAML-formatted data as well. Unlike CSV, which specifies a single row of headers, the fields for each object expressed in JSON or YAML can vary with each object, so each object will need to be validated individually. I think it's reasonable to replicate this pattern for CSV data, even if it's not technically necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7578