Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloning boolean custom fields does not work if their value is False #17096

Open
peteeckel opened this issue Aug 7, 2024 · 3 comments · May be fixed by #17113
Open

Cloning boolean custom fields does not work if their value is False #17096

peteeckel opened this issue Aug 7, 2024 · 3 comments · May be fixed by #17113
Assignees
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@peteeckel
Copy link
Contributor

Deployment Type

Self-hosted

NetBox Version

v4.0.8

Python Version

3.11

Steps to Reproduce

  1. Create a custom field 'test' with type 'Boolean', 'Is clonable' checked for an arbitrary object type, say ipam.IPAddress
  2. Set the custom field to False for an arbitrary IPAddress object and click on 'Save'
  3. Click on 'Clone'

Expected Behavior

The cloned object has its 'test' CF set to False

Observed Behavior

The cloned object has its 'test' CF set to None

If you look at the parameters of the URL for the 'Clone' button, the relevant part is test=. This is identical whether the CF 'test' was False for the original object or if it was undefined.

This is particularly relevant for required fields, as it makes it necessary to set the field explicitly for cloned objects even if cloning the field was enabled.

@peteeckel peteeckel added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Aug 7, 2024
@peteeckel peteeckel changed the title Cloning boolean custom fields does not work if their Value is False Cloning boolean custom fields does not work if their value is False Aug 7, 2024
@peteeckel
Copy link
Contributor Author

peteeckel commented Aug 7, 2024

I did not run the NetBox test suite yet, but there seems to be a trivial fix:

(netbox) [root@dns netbox]# git diff 
diff --git a/netbox/utilities/querydict.py b/netbox/utilities/querydict.py
index 78395758a..dbe2e4281 100644
--- a/netbox/utilities/querydict.py
+++ b/netbox/utilities/querydict.py
@@ -55,7 +55,7 @@ def prepare_cloned_fields(instance):
     for key, value in attrs.items():
         if type(value) in (list, tuple):
             params.extend([(key, v) for v in value])
-        elif value is not False and value is not None:
+        elif value is not None:
             params.append((key, value))
         else:
             params.append((key, ''))

@arthanson arthanson added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation severity: low Does not significantly disrupt application functionality, or a workaround is available and removed status: needs triage This issue is awaiting triage by a maintainer labels Aug 9, 2024
@arthanson arthanson removed their assignment Aug 9, 2024
@arthanson
Copy link
Collaborator

@peteeckel do you want to take this one?

@peteeckel
Copy link
Contributor Author

peteeckel commented Aug 9, 2024

@peteeckel do you want to take this one?

Sure, I'll be glad to.

@arthanson arthanson added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity: low Does not significantly disrupt application functionality, or a workaround is available status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants