[PR #20276] [MERGED] Fixes #20221: JSON CustomField does not coerce {} to null #15869

Closed
opened 2025-12-30 00:24:30 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20276
Author: @jnovinger
Created: 9/5/2025
Status: Merged
Merged: 9/5/2025
Merged by: @jeremystretch

Base: mainHead: 20221-json-custom-field-cant-handle-empty-object-as-default


📝 Commits (1)

  • e864520 Fixes #20221: JSON CustomField does not coerce {} to null

📊 Changes

3 files changed (+58 additions, -2 deletions)

View changed files

📝 netbox/extras/models/customfields.py (+1 -1)
📝 netbox/extras/tests/test_customfields.py (+56 -0)
📝 netbox/utilities/templates/builtins/customfield_value.html (+1 -1)

📄 Description

Fixes: #20221

This fix actually fixes this for all valid JSON values that evaluate to False in Python when loaded and cast to bool:
bool(json.loads(<val>)).

  • {}
  • []
  • 0
  • False

This does not change the behavior of () or "" which are both explicitly cited as "empty" values on JSONField.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20276 **Author:** [@jnovinger](https://github.com/jnovinger) **Created:** 9/5/2025 **Status:** ✅ Merged **Merged:** 9/5/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `main` ← **Head:** `20221-json-custom-field-cant-handle-empty-object-as-default` --- ### 📝 Commits (1) - [`e864520`](https://github.com/netbox-community/netbox/commit/e864520821f5cbc41f8314178256ac6a793a7138) Fixes #20221: JSON CustomField does not coerce `{}` to null ### 📊 Changes **3 files changed** (+58 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `netbox/extras/models/customfields.py` (+1 -1) 📝 `netbox/extras/tests/test_customfields.py` (+56 -0) 📝 `netbox/utilities/templates/builtins/customfield_value.html` (+1 -1) </details> ### 📄 Description ### Fixes: #20221 This fix actually fixes this for all valid JSON values that evaluate to `False` in Python when loaded and cast to bool: `bool(json.loads(<val>))`. - `{}` - `[]` - `0` - `False` This does not change the behavior of `()` or `""` which are both explicitly cited as "empty" values on `JSONField`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:24:30 +01:00
adam closed this issue 2025-12-30 00:24:30 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15869