diff --git a/netbox_acls/forms/models.py b/netbox_acls/forms/models.py index e034da6..c17a8d9 100644 --- a/netbox_acls/forms/models.py +++ b/netbox_acls/forms/models.py @@ -239,18 +239,20 @@ def clean(self): host_type: [error_same_acl_name], "name": [error_same_acl_name], } - if self.instance.pk: - # Check if Access List has no existing rules before change the Access List's type. - if ( + if ( + self.instance.pk + and ( acl_type == ACLTypeChoices.TYPE_EXTENDED and self.instance.aclstandardrules.exists() - ) or ( + ) + or ( acl_type == ACLTypeChoices.TYPE_STANDARD and self.instance.aclextendedrules.exists() - ): - error_message["type"] = [ - "This ACL has ACL rules associated, CANNOT change ACL type.", - ] + ) + ): + error_message["type"] = [ + "This ACL has ACL rules associated, CANNOT change ACL type.", + ] if error_message: raise forms.ValidationError(error_message)