Sites CSV Import - "Status" not a required field #5389

Closed
opened 2025-12-29 19:27:24 +01:00 by adam · 4 comments
Owner

Originally created by @WillIrvine on GitHub (Sep 20, 2021).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.0.2

Python version

3.7

Steps to Reproduce

  1. During normal site creation "Status" is a required field
    image

  2. During CSV Import, "Status" is not listed as a required field and can be imported without one
    image
    image
    image

Expected Behavior

Expect CSV Import to display error, and sites not to be added

Observed Behavior

Sites are added without Status

Originally created by @WillIrvine on GitHub (Sep 20, 2021). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.0.2 ### Python version 3.7 ### Steps to Reproduce 1. During normal site creation "Status" is a required field ![image](https://user-images.githubusercontent.com/32685892/133948891-27e16e67-5084-4ce5-976d-71be7521ee1a.png) 2. During CSV Import, "Status" is not listed as a required field and can be imported without one ![image](https://user-images.githubusercontent.com/32685892/133948957-cd7eed42-4164-456f-ba13-ddf1b3152476.png) ![image](https://user-images.githubusercontent.com/32685892/133950744-148e7827-1083-411a-9d53-cce1d98e32f3.png) ![image](https://user-images.githubusercontent.com/32685892/133949069-f4ef4b70-3085-445d-b8fb-b277bea8c123.png) ### Expected Behavior Expect CSV Import to display error, and sites not to be added ### Observed Behavior Sites are added without Status
adam added the type: bugstatus: accepted labels 2025-12-29 19:27:24 +01:00
adam closed this issue 2025-12-29 19:27:25 +01:00
Author
Owner

@WillIrvine commented on GitHub (Sep 20, 2021):

Having a quick look there are some other models where this same issue exists:

  • Racks,
  • IP Addresses,
  • Virtual Machines,
  • Circuits,
  • Power Feeds

Happy to put in a PR to fix all these, but as there are quite a few I want to make sure it wasn't an intentional design choice first

@WillIrvine commented on GitHub (Sep 20, 2021): Having a quick look there are some other models where this same issue exists: - Racks, - IP Addresses, - Virtual Machines, - Circuits, - Power Feeds Happy to put in a PR to fix all these, but as there are quite a few I want to make sure it wasn't an intentional design choice first
Author
Owner

@jeremystretch commented on GitHub (Sep 20, 2021):

This is a strange quirk of the CSV import logic. In the normal HTML form (object add/edit), you have a required field that's already populated with a default value, and it's not possible to select an empty value.

With CSV import, the set of form fields is dynamic and depends on which columns the user has defined. Typically, they either add the status column and define values for each object, or omit the column and rely on the default value (active). However, it seems we're missing validation to guard against the case where the column is defined but empty.

We could fix this by simply designating status as a required field, but that's a tad heavy-handed, since it would be more convenient for users to omit the column when the default value suffices. And unfortunately, specifying an initial value for the form field won't work because it gets overwritten by the "empty" column.

The optimal approach is probably to improve how we initialize the CSV model forms, to add individual fields dynamically in response to the column headers that are passed. I need to dig into this some more.

@jeremystretch commented on GitHub (Sep 20, 2021): This is a strange quirk of the CSV import logic. In the normal HTML form (object add/edit), you have a required field that's already populated with a default value, and it's not possible to select an empty value. With CSV import, the set of form fields is dynamic and depends on which columns the user has defined. Typically, they either add the `status` column and define values for each object, or omit the column and rely on the default value (active). However, it seems we're missing validation to guard against the case where the column is defined but empty. We _could_ fix this by simply designating `status` as a required field, but that's a tad heavy-handed, since it would be more convenient for users to omit the column when the default value suffices. And unfortunately, specifying an initial value for the form field won't work because it gets overwritten by the "empty" column. The optimal approach is probably to improve how we initialize the CSV model forms, to add individual fields dynamically in response to the column headers that are passed. I need to dig into this some more.
Author
Owner

@WillIrvine commented on GitHub (Sep 21, 2021):

Thanks Jeremy,

I wouldn't be against it being a required field for a few reasons.

  • When importing in bulk i think its important not to assume data, single additions are fine through the UI as the user can see the default in front of them, this isn't the case with an import.
  • If you're importing a site you have to go to the effort of adding a slug anyway, this is another variable that is usually handled by the UI
  • If someone wants all sites to be imported as planned, adding this to the end of a csv file is trivial

However no problem if you prefer the other way, both work for me

@WillIrvine commented on GitHub (Sep 21, 2021): Thanks Jeremy, I wouldn't be against it being a required field for a few reasons. - When importing in bulk i think its important not to assume data, single additions are fine through the UI as the user can see the default in front of them, this isn't the case with an import. - If you're importing a site you have to go to the effort of adding a slug anyway, this is another variable that is usually handled by the UI - If someone wants all sites to be imported as planned, adding this to the end of a csv file is trivial However no problem if you prefer the other way, both work for me
Author
Owner

@jeremystretch commented on GitHub (Sep 28, 2021):

When importing in bulk i think its important not to assume data, single additions are fine through the UI as the user can see the default in front of them, this isn't the case with an import.

Agreed; we should require the user to be explicit in such a case where the default value is not pre-populated. I've updated the import forms to make all choice fields with default values required fields.

@jeremystretch commented on GitHub (Sep 28, 2021): > When importing in bulk i think its important not to assume data, single additions are fine through the UI as the user can see the default in front of them, this isn't the case with an import. Agreed; we should require the user to be explicit in such a case where the default value is not pre-populated. I've updated the import forms to make all choice fields with default values required fields.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5389