Skip to content

Commit 82932ae

Browse files
committed
Fixes #8102 - Add validation around assigned objects
1 parent 14fc37a commit 82932ae

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

docs/release-notes/version-3.1.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* [#8088](https://github.com/netbox-community/netbox/issues/8088) - Improve legibility of text in labels with light-colored backgrounds
2323
* [#8092](https://github.com/netbox-community/netbox/issues/8092) - Rack elevations should not include device asset tags
2424
* [#8096](https://github.com/netbox-community/netbox/issues/8096) - Fix DataError during change logging of objects with very long string representations
25+
* [#8102](https://github.com/netbox-community/netbox/issues/8102) - Cause validation error when editing IPAddress when more than one object is selected for assignment
2526

2627
---
2728

netbox/ipam/forms/models.py

+14
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,20 @@ def __init__(self, *args, **kwargs):
461461
def clean(self):
462462
super().clean()
463463

464+
if self.cleaned_data['interface'] and self.cleaned_data['vminterface'] and self.cleaned_data['fhrpgroup']:
465+
self.add_error('interface', "Can only assign an interface, VM interface or FHRP group")
466+
self.add_error('vminterface', "Can only assign an interface, VM interface or FHRP group")
467+
self.add_error('fhrpgroup', "Can only assign an interface, VM interface or FHRP group")
468+
elif self.cleaned_data['interface'] and self.cleaned_data['vminterface']:
469+
self.add_error('interface', "Can only assign an interface or VM interface")
470+
self.add_error('vminterface', "Can only assign an interface or VM interface")
471+
elif self.cleaned_data['interface'] and self.cleaned_data['fhrpgroup']:
472+
self.add_error('interface', "Can only assign an interface or FHRP group")
473+
self.add_error('fhrpgroup', "Can only assign an interface or FHRP group")
474+
elif self.cleaned_data['vminterface'] and self.cleaned_data['fhrpgroup']:
475+
self.add_error('vminterface', "Can only assign an VM interface or FHRP group")
476+
self.add_error('fhrpgroup', "Can only assign an VM interface or FHRP group")
477+
464478
# Handle object assignment
465479
if self.cleaned_data['interface']:
466480
self.instance.assigned_object = self.cleaned_data['interface']

0 commit comments

Comments
 (0)