Skip to content

Commit 45c705f

Browse files
committed
Fix KeyError for type
Not all fields are always present. When changing an attribute type is not present in the form because it can only be setup during Attribute creation.
1 parent 14561cd commit 45c705f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

serveradmin/serverdb/forms.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ class Meta:
4141
fields = '__all__'
4242

4343
def clean(self):
44-
if self.cleaned_data['type'] != 'relation' and self.cleaned_data['target_servertype'] is not None:
44+
attr_type = self.cleaned_data.get('type') or self.instance.type # New or existing attribute ?
45+
46+
if attr_type != 'relation' and self.cleaned_data.get('target_servertype') is not None:
4547
raise ValidationError('Attribute type must be relation when target servertype is selected!')
4648

47-
if self.cleaned_data['type'] == 'inet' and self.cleaned_data['multi'] is True:
49+
if attr_type == 'inet' and self.cleaned_data.get('multi') is True:
4850
raise ValidationError('Multi attributes of type inet are not supported!')
4951

5052
super().clean()

0 commit comments

Comments
 (0)