Skip to content

Conversation

@renatoalmeidaoliveira
Copy link
Contributor

Fixes: #17796 Custom Field Choices -> Create & Add Another causes IndexError

  • In the current release this issue doesn't raises an Exception, but setups a wrong vaule to the form after clicking in Create & Add Another
  • The fix consists in convert the array query into a string to fit the Form field that is an CharField
  • It should be possible to change the behaiviour of prepare_cloned_fields, but IMO that may lead to unwanted collateral effects, and its leads to a more complex solution

Copy link
Collaborator

@arthanson arthanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@renatoalmeidaoliveira This fixes the issue and works, but I'm a bit uncomfortable with the code, it seems like this is patching the symptom rather than the initial problem. When we do the add-another it looks like it is getting sent in as a stringified tuple and your code here is deconstructing it. Can we look at why the add-another code is passing it in like this and can it just be made to pass it in the same as the edit case? I want to make sure we understand why this is different in the fist-place - if it can't be fixed there then can you please add a description in the PR why it is being passed in differently.

@renatoalmeidaoliveira
Copy link
Contributor Author

@arthanson I think the "real" problem relies in the different field type between the form and the model.
The CustomFieldChoiceSetForm uses a CharField for the extra_choices fields code
While the CustomFieldChoiceSet model uses an ArrayField type for extra_choices code
Because of the type difference there must be some kind of patch that convert those types.

@arthanson
Copy link
Collaborator

@renatoalmeidaoliveira can you add a TODO comment in the code stating what the fix is for and your note re the CharField vs ArrayField, mention that if they are refactored to use the same type then the fix could be removed.

@arthanson arthanson merged commit cffb99c into netbox-community:main Feb 25, 2025
3 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom Field Choices -> Create & Add Another causes IndexError

2 participants