Skip to content

Commit e1169e7

Browse files
Fixes #11345 - Fix module validation (#11346)
* Make sure we bail out if field validation failed when importing modules * Tweak form validation logic Co-authored-by: jeremystretch <[email protected]>
1 parent 5975dbc commit e1169e7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

netbox/dcim/forms/common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,18 @@ class ModuleCommonForm(forms.Form):
5656
def clean(self):
5757
super().clean()
5858

59-
replicate_components = self.cleaned_data.get("replicate_components")
60-
adopt_components = self.cleaned_data.get("adopt_components")
59+
replicate_components = self.cleaned_data.get('replicate_components')
60+
adopt_components = self.cleaned_data.get('adopt_components')
6161
device = self.cleaned_data.get('device')
6262
module_type = self.cleaned_data.get('module_type')
6363
module_bay = self.cleaned_data.get('module_bay')
6464

6565
if adopt_components:
6666
self.instance._adopt_components = True
6767

68-
# Bail out if we are not installing a new module or if we are not replicating components
69-
if self.instance.pk or not replicate_components:
68+
# Bail out if we are not installing a new module or if we are not replicating components (or if
69+
# validation has already failed)
70+
if self.errors or self.instance.pk or not replicate_components:
7071
self.instance._disable_replication = True
7172
return
7273

netbox/dcim/models/devices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ def get_status_color(self):
961961
def clean(self):
962962
super().clean()
963963

964-
if self.module_bay.device != self.device:
964+
if hasattr(self, "module_bay") and (self.module_bay.device != self.device):
965965
raise ValidationError(
966966
f"Module must be installed within a module bay belonging to the assigned device ({self.device})."
967967
)

0 commit comments

Comments
 (0)