Add tenant and group uniqueness constraint if tenant belongs to a group #6988

Closed
opened 2025-12-29 19:47:31 +01:00 by adam · 5 comments
Owner

Originally created by @abhi1693 on GitHub (Sep 15, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.2.2

Feature type

Change to existing functionality

Proposed functionality

Add unique_together for name and group on the Tenant model

Use case

I have a few end-users that have exact same name but they belong to different companies. We have modelled the companies as tenant groups on NetBox. I'd like to add two different people both named Tim to Company1 and Company2. In future, I could have another Tim who does not belong to any groups.

In all cases, I would like the validation by the group (if associated) just how contacts work.

We also use the tenant in our invoicing so adding a name like Tim 1 does not work for us as this would be reflected on the bill sent to the customer.

Adding the uniqueness constraint should not break anything existing either since it was not possible to have two Tims in the system anyhow.

Previously raised as bug #10373 but closed

Database changes

Add unique_together for name and group on the Tenant model

External dependencies

No response

Originally created by @abhi1693 on GitHub (Sep 15, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.2.2 ### Feature type Change to existing functionality ### Proposed functionality Add `unique_together` for `name` and `group` on the `Tenant` model ### Use case I have a few end-users that have exact same name but they belong to different companies. We have modelled the companies as tenant groups on NetBox. I'd like to add two different people both named `Tim` to `Company1` and `Company2`. In future, I could have another `Tim` who does not belong to any groups. In all cases, I would like the validation by the group (if associated) just how contacts work. We also use the `tenant` in our invoicing so adding a name like `Tim 1` does not work for us as this would be reflected on the bill sent to the customer. Adding the uniqueness constraint should not break anything existing either since it was not possible to have two `Tims` in the system anyhow. Previously raised as bug #10373 but closed ### Database changes Add `unique_together` for `name` and `group` on the `Tenant` model ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 19:47:31 +01:00
adam closed this issue 2025-12-29 19:47:31 +01:00
Author
Owner

@abhi1693 commented on GitHub (Sep 16, 2022):

@ITJamie I'm not asking to disallow global unique. I'm instead asking to make the tenant scope limited to the group only if it has one. If the tenant does not have a group, then it should work the same way it is working now.

@abhi1693 commented on GitHub (Sep 16, 2022): @ITJamie I'm not asking to disallow global unique. I'm instead asking to make the tenant scope limited to the group only if it has one. If the tenant does not have a group, then it should work the same way it is working now.
Author
Owner

@kprince28 commented on GitHub (Sep 20, 2022):

I have a similar issue where I'm trying to import data from our existing CMDB to our new NetBox installation. Today, I ran into the same issue wherein couple of my tenants though belong to different groups with different resources are not being added. I'm using REST APIs for perfomring the calls. I like the idea to limit the scope of the tenant into the group but also keep them unique if do not belong to any group.

If it's not possible, atleast remove the name uniqueness so that I can create my custom validator to implement my business logic.

@kprince28 commented on GitHub (Sep 20, 2022): I have a similar issue where I'm trying to import data from our existing CMDB to our new NetBox installation. Today, I ran into the same issue wherein couple of my tenants though belong to different groups with different resources are not being added. I'm using REST APIs for perfomring the calls. I like the idea to limit the scope of the tenant into the group but also keep them unique if do not belong to any group. If it's not possible, atleast remove the name uniqueness so that I can create my custom validator to implement my business logic.
Author
Owner

@jeremystretch commented on GitHub (Oct 3, 2022):

Just a quick implementation note: Per #10361 all uniqueness constraints in NetBox v3.4+ are now being done using UniqueConstraint classes rather than unique_together. This actually makes it much easier to implement conditional logic, as we no longer need to add a custom validation method to the model.

@jeremystretch commented on GitHub (Oct 3, 2022): Just a quick implementation note: Per #10361 all uniqueness constraints in NetBox v3.4+ are now being done using UniqueConstraint classes rather than `unique_together`. This actually makes it much easier to implement conditional logic, as we no longer need to add a custom validation method to the model.
Author
Owner

@abhi1693 commented on GitHub (Oct 11, 2022):

@jeremystretch Would the new implementation help in solving this issue in any way? If the core does not implement a solution, will I be able to override the conditional logic?

@abhi1693 commented on GitHub (Oct 11, 2022): @jeremystretch Would the new implementation help in solving this issue in any way? If the core does not implement a solution, will I be able to override the conditional logic?
Author
Owner

@github-actions[bot] commented on GitHub (Dec 11, 2022):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Dec 11, 2022): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6988