Skip to content

Commit b2e05aa

Browse files
committed
Closes #5531: Ensure consistent calls to parent clean() methods for models, forms
1 parent cc1a43e commit b2e05aa

File tree

9 files changed

+28
-1
lines changed

9 files changed

+28
-1
lines changed

netbox/dcim/forms.py

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class ComponentForm(BootstrapMixin, forms.Form):
134134
)
135135

136136
def clean(self):
137+
super().clean()
137138

138139
# Validate that the number of components being created from both the name_pattern and label_pattern are equal
139140
if self.cleaned_data['label_pattern']:
@@ -1438,6 +1439,7 @@ def __init__(self, *args, **kwargs):
14381439
self.fields['rear_port_set'].choices = choices
14391440

14401441
def clean(self):
1442+
super().clean()
14411443

14421444
# Validate that the number of ports being created equals the number of selected (rear port, position) tuples
14431445
front_port_count = len(self.cleaned_data['name_pattern'])
@@ -2929,6 +2931,7 @@ def __init__(self, *args, **kwargs):
29292931
self.fields['lag'].widget.attrs['disabled'] = True
29302932

29312933
def clean(self):
2934+
super().clean()
29322935

29332936
# Untagged interfaces cannot be assigned tagged VLANs
29342937
if self.cleaned_data['mode'] == InterfaceModeChoices.MODE_ACCESS and self.cleaned_data['tagged_vlans']:
@@ -3077,6 +3080,7 @@ def __init__(self, *args, **kwargs):
30773080
self.fields['rear_port_set'].choices = choices
30783081

30793082
def clean(self):
3083+
super().clean()
30803084

30813085
# Validate that the number of ports being created equals the number of selected (rear port, position) tuples
30823086
front_port_count = len(self.cleaned_data['name_pattern'])
@@ -3909,6 +3913,7 @@ class Meta:
39093913
]
39103914

39113915
def clean(self):
3916+
super().clean()
39123917

39133918
# Validate length/unit
39143919
length = self.cleaned_data.get('length')

netbox/dcim/models/device_component_templates.py

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class Meta:
193193
unique_together = ('device_type', 'name')
194194

195195
def clean(self):
196+
super().clean()
196197

197198
# Validate power port assignment
198199
if self.power_port and self.power_port.device_type != self.device_type:
@@ -278,6 +279,7 @@ class Meta:
278279
)
279280

280281
def clean(self):
282+
super().clean()
281283

282284
# Validate rear port assignment
283285
if self.rear_port.device_type != self.device_type:

netbox/dcim/models/device_components.py

+6
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def to_csv(self):
316316
)
317317

318318
def clean(self):
319+
super().clean()
319320

320321
if self.maximum_draw is not None and self.allocated_draw is not None:
321322
if self.allocated_draw > self.maximum_draw:
@@ -425,6 +426,7 @@ def to_csv(self):
425426
)
426427

427428
def clean(self):
429+
super().clean()
428430

429431
# Validate power port assignment
430432
if self.power_port and self.power_port.device != self.device:
@@ -555,6 +557,7 @@ def to_csv(self):
555557
)
556558

557559
def clean(self):
560+
super().clean()
558561

559562
# Virtual interfaces cannot be connected
560563
if self.type in NONCONNECTABLE_IFACE_TYPES and (
@@ -668,6 +671,7 @@ def to_csv(self):
668671
)
669672

670673
def clean(self):
674+
super().clean()
671675

672676
# Validate rear port assignment
673677
if self.rear_port.device != self.device:
@@ -711,6 +715,7 @@ def get_absolute_url(self):
711715
return reverse('dcim:rearport', kwargs={'pk': self.pk})
712716

713717
def clean(self):
718+
super().clean()
714719

715720
# Check that positions count is greater than or equal to the number of associated FrontPorts
716721
frontport_count = self.frontports.count()
@@ -768,6 +773,7 @@ def to_csv(self):
768773
)
769774

770775
def clean(self):
776+
super().clean()
771777

772778
# Validate that the parent Device can have DeviceBays
773779
if not self.device.device_type.is_parent_device:

netbox/dcim/models/racks.py

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def to_objectchange(self, action):
109109
)
110110

111111
def clean(self):
112+
super().clean()
112113

113114
# Parent RackGroup (if any) must belong to the same Site
114115
if self.parent and self.parent.site != self.site:

netbox/extras/models/customfields.py

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def get_custom_fields(self):
4747
])
4848

4949
def clean(self):
50+
super().clean()
51+
5052
custom_fields = {cf.name: cf for cf in CustomField.objects.get_for_model(self)}
5153

5254
# Validate all field values
@@ -172,6 +174,8 @@ def remove_stale_data(self, content_types):
172174
obj.save()
173175

174176
def clean(self):
177+
super().clean()
178+
175179
# Validate the field's default value (if any)
176180
if self.default is not None:
177181
try:

netbox/extras/models/models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,15 @@ def __str__(self):
117117
return self.name
118118

119119
def clean(self):
120+
super().clean()
121+
122+
# At least one action type must be selected
120123
if not self.type_create and not self.type_delete and not self.type_update:
121124
raise ValidationError(
122125
"You must select at least one type: create, update, and/or delete."
123126
)
124127

128+
# CA file path requires SSL verification enabled
125129
if not self.ssl_verification and self.ca_file_path:
126130
raise ValidationError({
127131
'ca_file_path': 'Do not specify a CA certificate file if SSL verification is disabled.'
@@ -436,6 +440,7 @@ def get_absolute_url(self):
436440
return reverse('extras:configcontext', kwargs={'pk': self.pk})
437441

438442
def clean(self):
443+
super().clean()
439444

440445
# Verify that JSON data is provided as an object
441446
if type(self.data) is not dict:
@@ -482,7 +487,6 @@ def get_config_context(self):
482487
return data
483488

484489
def clean(self):
485-
486490
super().clean()
487491

488492
# Verify that JSON data is provided as an object

netbox/users/admin.py

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def __init__(self, *args, **kwargs):
169169
self.instance.actions.remove(action)
170170

171171
def clean(self):
172+
super().clean()
173+
172174
object_types = self.cleaned_data.get('object_types')
173175
constraints = self.cleaned_data.get('constraints')
174176

netbox/utilities/forms/forms.py

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class BulkRenameForm(forms.Form):
8282
)
8383

8484
def clean(self):
85+
super().clean()
8586

8687
# Validate regular expression in "find" field
8788
if self.cleaned_data['use_regex']:
@@ -124,6 +125,7 @@ class ImportForm(BootstrapMixin, forms.Form):
124125
)
125126

126127
def clean(self):
128+
super().clean()
127129

128130
data = self.cleaned_data['data']
129131
format = self.cleaned_data['format']

netbox/virtualization/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ def to_csv(self):
444444
)
445445

446446
def clean(self):
447+
super().clean()
447448

448449
# Validate untagged VLAN
449450
if self.untagged_vlan and self.untagged_vlan.site not in [self.virtual_machine.site, None]:

0 commit comments

Comments
 (0)