Cloning boolean custom fields does not work if their value is `False`
Deployment Type
Self-hosted
NetBox Version
v4.0.8
Python Version
3.11
Steps to Reproduce
- Create a custom field 'test' with type 'Boolean', 'Is clonable' checked for an arbitrary object type, say
ipam.IPAddress - Set the custom field to
Falsefor an arbitraryIPAddressobject and click on 'Save' - 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.
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 do you want to take this one?
@peteeckel do you want to take this one?
Sure, I'll be glad to.
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.
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.