From 22bb700f94d13c818c87445e0c170c72b2e05a80 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 3 Dec 2020 13:40:42 -0500 Subject: [PATCH] Fixes #5396: Fix uniqueness constraint for virtual machine names --- docs/release-notes/version-2.9.md | 1 + netbox/virtualization/models.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-2.9.md b/docs/release-notes/version-2.9.md index 563220cb5..e755e7b82 100644 --- a/docs/release-notes/version-2.9.md +++ b/docs/release-notes/version-2.9.md @@ -5,6 +5,7 @@ ### Bug Fixes * [#5383](https://github.com/netbox-community/netbox/issues/5383) - Fix setting user password via REST API +* [#5396](https://github.com/netbox-community/netbox/issues/5396) - Fix uniqueness constraint for virtual machine names --- diff --git a/netbox/virtualization/models.py b/netbox/virtualization/models.py index 7a8bd7595..72d84a908 100644 --- a/netbox/virtualization/models.py +++ b/netbox/virtualization/models.py @@ -319,10 +319,10 @@ class VirtualMachine(ChangeLoggedModel, ConfigContextModel, CustomFieldModel): # because Django does not consider two NULL fields to be equal, and thus will not trigger a violation # of the uniqueness constraint without manual intervention. if self.tenant is None and VirtualMachine.objects.exclude(pk=self.pk).filter( - name=self.name, tenant__isnull=True + name=self.name, cluster=self.cluster, tenant__isnull=True ): raise ValidationError({ - 'name': 'A virtual machine with this name already exists.' + 'name': 'A virtual machine with this name already exists in the assigned cluster.' }) super().validate_unique(exclude)