netbox icon indicating copy to clipboard operation
netbox copied to clipboard

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

Open peteeckel opened this issue 1 year ago • 4 comments

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 avatar Aug 07 '24 12:08 peteeckel

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, ''))

peteeckel avatar Aug 07 '24 12:08 peteeckel

@peteeckel do you want to take this one?

arthanson avatar Aug 09 '24 08:08 arthanson

@peteeckel do you want to take this one?

Sure, I'll be glad to.

peteeckel avatar Aug 09 '24 08:08 peteeckel

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] avatar Jun 17 '25 04:06 github-actions[bot]

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

github-actions[bot] avatar Jul 17 '25 04:07 github-actions[bot]