Skip to content

Commit 843b1fa

Browse files
authored
Merge pull request #97 from Onemind-Services-LLC/fix/value-error
Fixed value error when the instance does not exist
2 parents f8a592d + c382b67 commit 843b1fa

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

netbox_acls/forms/models.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,18 @@ def clean(self):
236236
host_type: [error_same_acl_name],
237237
"name": [error_same_acl_name],
238238
}
239-
# Check if Access List has no existing rules before change the Access List's type.
240-
if (
241-
acl_type == ACLTypeChoices.TYPE_EXTENDED
242-
and self.instance.aclstandardrules.exists()
243-
) or (
244-
acl_type == ACLTypeChoices.TYPE_STANDARD
245-
and self.instance.aclextendedrules.exists()
246-
):
247-
error_message["type"] = [
248-
"This ACL has ACL rules associated, CANNOT change ACL type.",
249-
]
239+
if self.instance.pk:
240+
# Check if Access List has no existing rules before change the Access List's type.
241+
if (
242+
acl_type == ACLTypeChoices.TYPE_EXTENDED
243+
and self.instance.aclstandardrules.exists()
244+
) or (
245+
acl_type == ACLTypeChoices.TYPE_STANDARD
246+
and self.instance.aclextendedrules.exists()
247+
):
248+
error_message["type"] = [
249+
"This ACL has ACL rules associated, CANNOT change ACL type.",
250+
]
250251

251252
if error_message:
252253
raise forms.ValidationError(error_message)

0 commit comments

Comments
 (0)