Duplicate device name, different site triggers uniqueness error #3512

Closed
opened 2025-12-29 18:29:35 +01:00 by adam · 0 comments
Owner

Originally created by @DanSheps on GitHub (Mar 27, 2020).

Environment

  • Python version: 3.6
  • NetBox version: 2.7.10

Steps to Reproduce

  1. Create two sites S1 & S2
  2. Create a device, D1 in site S1
  3. Create a device D1 in site S2

Expected Behavior

Create D1 in S2 successfully

Observed Behavior

Validation Error: "A device with this name already exists"

Reason

In validate_unique() on the device model, we are suppose to be looking for a device assigned to the same site with no tenant. However, we are not setting the site and instead only looking for a duplicate name.

Fix

1393 -            if Device.objects.exclude(pk=self.pk).filter(name=self.name, tenant__isnull=True):
1393 +            if Device.objects.exclude(pk=self.pk).filter(name=self.name, site=self.site, tenant__isnull=True):
Originally created by @DanSheps on GitHub (Mar 27, 2020). ### Environment * Python version: 3.6 * NetBox version: 2.7.10 ### Steps to Reproduce 1. Create two sites S1 & S2 2. Create a device, D1 in site S1 3. Create a device D1 in site S2 ### Expected Behavior Create D1 in S2 successfully ### Observed Behavior Validation Error: "A device with this name already exists" ### Reason In validate_unique() on the device model, we are suppose to be looking for a device assigned to the same site with no tenant. However, we are not setting the site and instead only looking for a duplicate name. ### Fix ``` 1393 - if Device.objects.exclude(pk=self.pk).filter(name=self.name, tenant__isnull=True): 1393 + if Device.objects.exclude(pk=self.pk).filter(name=self.name, site=self.site, tenant__isnull=True):
adam added the type: bugstatus: accepted labels 2025-12-29 18:29:35 +01:00
adam closed this issue 2025-12-29 18:29:35 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3512