Jelajahi Sumber

Fixes: #4415 - Add site on validate_unique() for device model

Daniel Sheppard 5 tahun lalu
induk
melakukan
785119f5bb
2 mengubah file dengan 2 tambahan dan 1 penghapusan
  1. 1 0
      docs/release-notes/version-2.7.md
  2. 1 1
      netbox/dcim/models/__init__.py

+ 1 - 0
docs/release-notes/version-2.7.md

@@ -21,6 +21,7 @@
 * [#4340](https://github.com/netbox-community/netbox/issues/4340) - Enforce unique constraints for device and virtual machine names in the API
 * [#4340](https://github.com/netbox-community/netbox/issues/4340) - Enforce unique constraints for device and virtual machine names in the API
 * [#4343](https://github.com/netbox-community/netbox/issues/4343) - Fix Markdown support for tables
 * [#4343](https://github.com/netbox-community/netbox/issues/4343) - Fix Markdown support for tables
 * [#4365](https://github.com/netbox-community/netbox/issues/4365) - Fix exception raised on IP address bulk add view
 * [#4365](https://github.com/netbox-community/netbox/issues/4365) - Fix exception raised on IP address bulk add view
+* [#4415](https://github.com/netbox-community/netbox/issues/4415) - Fix duplicate name validation on device model
 
 
 ---
 ---
 
 

+ 1 - 1
netbox/dcim/models/__init__.py

@@ -1390,7 +1390,7 @@ class Device(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.name and self.tenant is None:
         if self.name and self.tenant is None:
-            if Device.objects.exclude(pk=self.pk).filter(name=self.name, tenant__isnull=True):
+            if Device.objects.exclude(pk=self.pk).filter(name=self.name, site=self.site, tenant__isnull=True):
                 raise ValidationError({
                 raise ValidationError({
                     'name': 'A device with this name already exists.'
                     'name': 'A device with this name already exists.'
                 })
                 })