Fixes #5396: Fix uniqueness constraint for virtual machine names

This commit is contained in:
Jeremy Stretch 2020-12-03 13:40:42 -05:00
parent a4b2e1f2e2
commit 22bb700f94
2 changed files with 3 additions and 2 deletions

View File

@ -5,6 +5,7 @@
### Bug Fixes ### Bug Fixes
* [#5383](https://github.com/netbox-community/netbox/issues/5383) - Fix setting user password via REST API * [#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
--- ---

View File

@ -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 # 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. # of the uniqueness constraint without manual intervention.
if self.tenant is None and VirtualMachine.objects.exclude(pk=self.pk).filter( 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({ 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) super().validate_unique(exclude)