Removal of an option in a CustomFieldChoice does not update objects with the choiceset and the option selected #10270

Closed
opened 2025-12-29 21:29:13 +01:00 by adam · 5 comments
Owner

Originally created by @cruse1977 on GitHub (Sep 20, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

NetBox Cloud

NetBox Version

v4.1.1

Python Version

3.12

Steps to Reproduce

  • Create a CustomFieldChoices with some options (A,B,C)
image
  • Create a Device Z
  • Create a custom field of type selection with the CustomFieldChoices
  • Assign the custom field to Device
  • On Device Z, on the custom field, assign choice B
image
  • In the CustomFieldChoiceSet delete option B
image
  • View Device Z

Expected Behavior

The selected option on the choiceset attached to device Z should be null/none, due to the option removal

Observed Behavior

Option B remains until the object is edited or saved, despite no longer existing.

image

Note - Due to the options inherent within ChoiceSets (eg: Non Null, default etc) but I'm trying to ascertain if this is a bug (ie: NetBox should warn/error on Objects with this choice selected) or expected behaviour - hence requesting feedback

Originally created by @cruse1977 on GitHub (Sep 20, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type NetBox Cloud ### NetBox Version v4.1.1 ### Python Version 3.12 ### Steps to Reproduce - Create a CustomFieldChoices with some options (A,B,C) <img width="1188" alt="image" src="https://github.com/user-attachments/assets/220f816b-379b-4170-9755-d80f9c9300d0"> - Create a Device Z - Create a custom field of type selection with the CustomFieldChoices - Assign the custom field to Device - On Device Z, on the custom field, assign choice B <img width="1110" alt="image" src="https://github.com/user-attachments/assets/079d8a7c-c863-4f76-a90a-cc5642801c34"> - In the CustomFieldChoiceSet delete option B <img width="2254" alt="image" src="https://github.com/user-attachments/assets/57c3d219-6dae-4d80-9557-1bbd9af33121"> - View Device Z ### Expected Behavior The selected option on the choiceset attached to device Z should be null/none, due to the option removal ### Observed Behavior Option B remains until the object is edited or saved, despite no longer existing. <img width="1115" alt="image" src="https://github.com/user-attachments/assets/f5005d80-6a32-4f25-b17d-f70f21f0c62a"> Note - Due to the options inherent within ChoiceSets (eg: Non Null, default etc) but I'm trying to ascertain if this is a bug (ie: NetBox should warn/error on Objects with this choice selected) or expected behaviour - hence requesting feedback
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:29:13 +01:00
adam closed this issue 2025-12-29 21:29:13 +01:00
Author
Owner

@arthanson commented on GitHub (Sep 23, 2024):

This should throw a validation error if you try to delete a choice and there are items assigned to that choice.

@arthanson commented on GitHub (Sep 23, 2024): This should throw a validation error if you try to delete a choice and there are items assigned to that choice.
Author
Owner

@ghost commented on GitHub (Sep 23, 2024):

just my 0.02 cents, I prefer the exiting method.
You should be able to remove options from a choice set, and objects currently referencing that option should maintain their selection until the next time you attempt to edit that object.

Removing a choice set doesn't make the choices selection on each object automatically invalid. It just means it's no longer available as a selection.

@ghost commented on GitHub (Sep 23, 2024): just my 0.02 cents, I prefer the exiting method. You should be able to remove options from a choice set, and objects currently referencing that option should maintain their selection until the next time you attempt to edit that object. Removing a choice set doesn't make the choices selection on each object automatically invalid. It just means it's no longer available as a selection.
Author
Owner

@bctiemann commented on GitHub (Sep 24, 2024):

I think I agree with @goteamkor -- I can think of a lot of use cases where you would want to retain the data from a time when an option was available, but have that option not be available to select anymore. Like if you had a list of "Supported Devices" and you had previously assigned a value from that list to a "device" field on some other model; and then that device becomes no longer supported, so you remove it from the list. I'd much rather have the device field stay filled in, to preserve the history of that object, and allow the freedom to define the custom field choices such that that device is no longer offered as "supported".

@bctiemann commented on GitHub (Sep 24, 2024): I think I agree with @goteamkor -- I can think of a lot of use cases where you would want to retain the data from a time when an option was available, but have that option not be available to select anymore. Like if you had a list of "Supported Devices" and you had previously assigned a value from that list to a "device" field on some other model; and then that device becomes no longer supported, so you remove it from the list. I'd much rather have the device field stay filled in, to preserve the history of that object, and allow the freedom to define the custom field choices such that that device is no longer offered as "supported".
Author
Owner

@jeremystretch commented on GitHub (Sep 24, 2024):

Removing a choice set doesn't make the choices selection on each object automatically invalid.

It does, by definition. Attempting to re-save an object with a selected choice that is no longer available will fail (or nullify that choice, depending on the mechanism). Allowing invalid choices to be defined would defeat the purpose of defining a set of choices in the first place.

@jeremystretch commented on GitHub (Sep 24, 2024): > Removing a choice set doesn't make the choices selection on each object automatically invalid. It does, by definition. Attempting to re-save an object with a selected choice that is no longer available will fail (or nullify that choice, depending on the mechanism). Allowing invalid choices to be defined would defeat the purpose of defining a set of choices in the first place.
Author
Owner

@ghost commented on GitHub (Sep 25, 2024):

We're not talking about opening the object and trying to save it again with the same value that is no longer a valid option. I'm talking specifically about the FR here, which is to alter the behavior of what happens when removing an option from a choice set.

The proposed change would make the removal of an option from a choiceset set fail when trying to save because there are objects out there that still reference that option.
My statement was that just because an option has been removed from a choice set and there are objects that still have that option set shouldn't make the removal of the option from the choiceset fail.

You shouldn't have to go remove every reference to the option before netbox will let you remove the option from the choice set.

Basically what I'm advocating here is that existing behavior is maintained. I disagree with @arthanson that a validation error should be thrown when trying to remove an option from a choice set when objects reference that option. And I also disagree with @cruse1977 that when removing the option, all objects that reference that option should change to "null/none"

EDIT: I see there is already a pull request created. (https://github.com/netbox-community/netbox/pull/17591) I hope this doesn't get merged.

@ghost commented on GitHub (Sep 25, 2024): We're not talking about opening the object and trying to save it again with the same value that is no longer a valid option. I'm talking specifically about the FR here, which is to alter the behavior of what happens when removing an option from a choice set. The proposed change would make the removal of an option from a choiceset set fail when trying to save because there are objects out there that still reference that option. My statement was that just because an option has been removed from a choice set and there are objects that still have that option set shouldn't make the removal of the option from the choiceset fail. You shouldn't have to go remove every reference to the option before netbox will let you remove the option from the choice set. Basically what I'm advocating here is that existing behavior is maintained. I disagree with @arthanson that a validation error should be thrown when trying to remove an option from a choice set when objects reference that option. And I also disagree with @cruse1977 that when removing the option, all objects that reference that option should change to "null/none" EDIT: I see there is already a pull request created. (https://github.com/netbox-community/netbox/pull/17591) I hope this doesn't get merged.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10270