Skip to content

Commit 71449b3

Browse files
committed
Fixes #7304: Require explicit values for all required choice fields during CSV import
1 parent 16f5e23 commit 71449b3

File tree

9 files changed

+21
-29
lines changed

9 files changed

+21
-29
lines changed

docs/release-notes/version-3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Bug Fixes
1212

1313
* [#7294](https://github.com/netbox-community/netbox/issues/7294) - Fix SVG rendering for cable traces ending at unoccupied front ports
14+
* [#7304](https://github.com/netbox-community/netbox/issues/7304) - Require explicit values for all required choice fields during CSV import
1415
* [#7321](https://github.com/netbox-community/netbox/issues/7321) - Don't overwrite multi-select custom fields during bulk edit
1516
* [#7324](https://github.com/netbox-community/netbox/issues/7324) - Fix TypeError exception in web UI when filtering objects using single-choice filters
1617
* [#7333](https://github.com/netbox-community/netbox/issues/7333) - Prevent inadvertent deletion of prior change records when deleting objects

netbox/circuits/forms/bulk_import.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ class CircuitCSVForm(CustomFieldModelCSVForm):
6060
)
6161
status = CSVChoiceField(
6262
choices=CircuitStatusChoices,
63-
required=False,
6463
help_text='Operational status'
6564
)
6665
tenant = CSVModelChoiceField(

netbox/circuits/tests/test_views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ def setUpTestData(cls):
122122
}
123123

124124
cls.csv_data = (
125-
"cid,provider,type",
126-
"Circuit 4,Provider 1,Circuit Type 1",
127-
"Circuit 5,Provider 1,Circuit Type 1",
128-
"Circuit 6,Provider 1,Circuit Type 1",
125+
"cid,provider,type,status",
126+
"Circuit 4,Provider 1,Circuit Type 1,active",
127+
"Circuit 5,Provider 1,Circuit Type 1,active",
128+
"Circuit 6,Provider 1,Circuit Type 1,active",
129129
)
130130

131131
cls.bulk_edit_data = {

netbox/dcim/forms/bulk_import.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class Meta:
7070
class SiteCSVForm(CustomFieldModelCSVForm):
7171
status = CSVChoiceField(
7272
choices=SiteStatusChoices,
73-
required=False,
7473
help_text='Operational status'
7574
)
7675
region = CSVModelChoiceField(
@@ -156,7 +155,6 @@ class RackCSVForm(CustomFieldModelCSVForm):
156155
)
157156
status = CSVChoiceField(
158157
choices=RackStatusChoices,
159-
required=False,
160158
help_text='Operational status'
161159
)
162160
role = CSVModelChoiceField(
@@ -929,22 +927,18 @@ class PowerFeedCSVForm(CustomFieldModelCSVForm):
929927
)
930928
status = CSVChoiceField(
931929
choices=PowerFeedStatusChoices,
932-
required=False,
933930
help_text='Operational status'
934931
)
935932
type = CSVChoiceField(
936933
choices=PowerFeedTypeChoices,
937-
required=False,
938934
help_text='Primary or redundant'
939935
)
940936
supply = CSVChoiceField(
941937
choices=PowerFeedSupplyChoices,
942-
required=False,
943938
help_text='Supply type (AC/DC)'
944939
)
945940
phase = CSVChoiceField(
946941
choices=PowerFeedPhaseChoices,
947-
required=False,
948942
help_text='Single or three-phase'
949943
)
950944

netbox/dcim/tests/test_views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,10 @@ def setUpTestData(cls):
322322
}
323323

324324
cls.csv_data = (
325-
"site,location,name,width,u_height",
326-
"Site 1,,Rack 4,19,42",
327-
"Site 1,Location 1,Rack 5,19,42",
328-
"Site 2,Location 2,Rack 6,19,42",
325+
"site,location,name,status,width,u_height",
326+
"Site 1,,Rack 4,active,19,42",
327+
"Site 1,Location 1,Rack 5,active,19,42",
328+
"Site 2,Location 2,Rack 6,active,19,42",
329329
)
330330

331331
cls.bulk_edit_data = {
@@ -1991,10 +1991,10 @@ def setUpTestData(cls):
19911991
}
19921992

19931993
cls.csv_data = (
1994-
"site,power_panel,name,voltage,amperage,max_utilization",
1995-
"Site 1,Power Panel 1,Power Feed 4,120,20,80",
1996-
"Site 1,Power Panel 1,Power Feed 5,120,20,80",
1997-
"Site 1,Power Panel 1,Power Feed 6,120,20,80",
1994+
"site,power_panel,name,status,type,supply,phase,voltage,amperage,max_utilization",
1995+
"Site 1,Power Panel 1,Power Feed 4,active,primary,ac,single-phase,120,20,80",
1996+
"Site 1,Power Panel 1,Power Feed 5,active,primary,ac,single-phase,120,20,80",
1997+
"Site 1,Power Panel 1,Power Feed 6,active,primary,ac,single-phase,120,20,80",
19981998
)
19991999

20002000
cls.bulk_edit_data = {

netbox/extras/tests/test_customfields.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ def test_import(self):
506506
Import a Site in CSV format, including a value for each CustomField.
507507
"""
508508
data = (
509-
('name', 'slug', 'cf_text', 'cf_integer', 'cf_boolean', 'cf_date', 'cf_url', 'cf_select'),
510-
('Site 1', 'site-1', 'ABC', '123', 'True', '2020-01-01', 'http://example.com/1', 'Choice A'),
511-
('Site 2', 'site-2', 'DEF', '456', 'False', '2020-01-02', 'http://example.com/2', 'Choice B'),
512-
('Site 3', 'site-3', '', '', '', '', '', ''),
509+
('name', 'slug', 'status', 'cf_text', 'cf_integer', 'cf_boolean', 'cf_date', 'cf_url', 'cf_select'),
510+
('Site 1', 'site-1', 'active', 'ABC', '123', 'True', '2020-01-01', 'http://example.com/1', 'Choice A'),
511+
('Site 2', 'site-2', 'active', 'DEF', '456', 'False', '2020-01-02', 'http://example.com/2', 'Choice B'),
512+
('Site 3', 'site-3', 'active', '', '', '', '', '', ''),
513513
)
514514
csv_data = '\n'.join(','.join(row) for row in data)
515515

netbox/ipam/forms/bulk_import.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ class IPAddressCSVForm(CustomFieldModelCSVForm):
198198
)
199199
status = CSVChoiceField(
200200
choices=IPAddressStatusChoices,
201-
required=False,
202201
help_text='Operational status'
203202
)
204203
role = CSVChoiceField(

netbox/virtualization/forms/bulk_import.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class Meta:
6464
class VirtualMachineCSVForm(CustomFieldModelCSVForm):
6565
status = CSVChoiceField(
6666
choices=VirtualMachineStatusChoices,
67-
required=False,
6867
help_text='Operational status of device'
6968
)
7069
cluster = CSVModelChoiceField(

netbox/virtualization/tests/test_views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ def setUpTestData(cls):
194194
}
195195

196196
cls.csv_data = (
197-
"name,cluster",
198-
"Virtual Machine 4,Cluster 1",
199-
"Virtual Machine 5,Cluster 1",
200-
"Virtual Machine 6,Cluster 1",
197+
"name,status,cluster",
198+
"Virtual Machine 4,active,Cluster 1",
199+
"Virtual Machine 5,active,Cluster 1",
200+
"Virtual Machine 6,active,Cluster 1",
201201
)
202202

203203
cls.bulk_edit_data = {

0 commit comments

Comments
 (0)