Invalid choice when changing tenant #3222

Closed
opened 2025-12-29 18:26:51 +01:00 by adam · 3 comments
Owner

Originally created by @hSaria on GitHub (Jan 26, 2020).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.7.2

Steps to Reproduce

  1. Create tenant group tg1, tenant t1 in group tg1, and tenant t0 with no group
  2. Create site and set tenant to t1 (in a group)
  3. Edit the site, clean the tenant group, and set tenant to t0 (not in a group).

This affects any object that supports tenancy; I used Site as an example.

The chain is limiting the queryset, and therefore the choices, to only those in the current group during form initialization.

7a548e806d/netbox/tenancy/forms.py (L136-L140)

Expected Behavior

Tenant is changed

Observed Behavior

Validation error indicating that the choice is not available. The workaround is to remove the tenant entirely, save the object, then add the new tenant.

Originally created by @hSaria on GitHub (Jan 26, 2020). ### Environment * Python version: 3.6.8 * NetBox version: 2.7.2 ### Steps to Reproduce 1. Create tenant group `tg1`, tenant `t1` in group `tg1`, and tenant `t0` with no group 2. Create site and set tenant to `t1` (in a group) 3. Edit the site, clean the tenant group, and set tenant to `t0` (not in a group). > This affects any object that supports tenancy; I used Site as an example. The chain is limiting the queryset, and therefore the choices, to only those in the current group during form initialization. https://github.com/netbox-community/netbox/blob/7a548e806da74b6ae53529411c65400b080b67ef/netbox/tenancy/forms.py#L136-L140 ### Expected Behavior Tenant is changed ### Observed Behavior Validation error indicating that the choice is not available. The workaround is to remove the tenant entirely, save the object, then add the new tenant.
adam added the type: bugstatus: accepted labels 2025-12-29 18:26:51 +01:00
adam closed this issue 2025-12-29 18:26:51 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 28, 2020):

The issue seems to be that tenant_group is not being sent in the form data. The form relies upon tenant_group being set to null for validation. I'm not sure why the field is being omitted. (Other ForeignKey fields, such as region, are included even when null.)

Edit: The field is being omitted from the form data because it uses a multiselect widget.

@jeremystretch commented on GitHub (Jan 28, 2020): The issue seems to be that `tenant_group` is not being sent in the form data. The form relies upon `tenant_group` being set to `null` for validation. I'm not sure why the field is being omitted. (Other ForeignKey fields, such as region, are included even when null.) Edit: The field is being omitted from the form data because it uses a multiselect widget.
Author
Owner

@hSaria commented on GitHub (Jan 28, 2020):

Another related bug is selecting a tenant that is in a group, but not populating the tenant group field. Like most other hierarchical fields, the tenant group should only be there to limit the tenant choices (i.e. someone can pick a tenant without needing to specify the group).

I'm not sure if this related bug is fixed if the tenant group was included with value of null.

@hSaria commented on GitHub (Jan 28, 2020): Another related bug is selecting a tenant that is in a group, but not populating the tenant group field. Like most other hierarchical fields, the tenant group should only be there to limit the tenant choices (i.e. someone can pick a tenant without needing to specify the group). I'm not sure if this related bug is fixed if the tenant group was included with value of null.
Author
Owner

@hSaria commented on GitHub (Feb 10, 2020):

This is fixed indirectly with #3912.

@hSaria commented on GitHub (Feb 10, 2020): This is fixed indirectly with #3912.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3222