[Django] #32807: JSONField.bound_data raises TypeError when data is None

22 views
Skip to first unread message

Django

unread,
Jun 1, 2021, 12:42:05 PM6/1/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
-----------------------------------------+---------------------------
Reporter: strokirk | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 3.2
Severity: Normal | Keywords: JSONField
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+---------------------------
Hi,

When a bound form with no value provided for the JSONField is rendered, it
will currently crash.

{{{
class JSONForm(Form):
json_field = JSONField(required=False)
form = JSONForm({})
assert form.as_p()
}}}

raises

{{{
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
}}}

A fix has been created already by @AlexHill here:
https://github.com/django/django/pull/13844

--
Ticket URL: <https://code.djangoproject.com/ticket/32807>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 1, 2021, 2:34:00 PM6/1/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
------------------------------+-------------------------------------
Reporter: Dan Strokirk | Owner: Alex Hill
Type: Bug | Status: assigned
Component: Forms | Version: 3.2
Severity: Normal | Resolution:
Keywords: JSONField | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Alex Hill
* status: new => assigned
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/32807#comment:1>

Django

unread,
Jun 1, 2021, 2:42:12 PM6/1/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
------------------------------+-------------------------------------
Reporter: Dan Strokirk | Owner: Alex Hill
Type: Bug | Status: assigned
Component: Forms | Version: 3.2

Severity: Normal | Resolution:
Keywords: JSONField | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Regression in db19619545dd99a1d2502c72974d79eca33acff7.

--
Ticket URL: <https://code.djangoproject.com/ticket/32807#comment:2>

Django

unread,
Jun 1, 2021, 2:49:17 PM6/1/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
------------------------------+-------------------------------------
Reporter: Dan Strokirk | Owner: Alex Hill
Type: Bug | Status: assigned
Component: Forms | Version: 3.2

Severity: Normal | Resolution:
Keywords: JSONField | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32807#comment:3>

Django

unread,
Jun 1, 2021, 3:12:19 PM6/1/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
------------------------------+-------------------------------------
Reporter: Dan Strokirk | Owner: Alex Hill
Type: Bug | Status: assigned
Component: Forms | Version: 3.2

Severity: Normal | Resolution:
Keywords: JSONField | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
------------------------------+-------------------------------------

Comment (by Jacob Walls):

[https://github.com/django/django/pull/13844 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32807#comment:4>

Django

unread,
Jun 24, 2021, 11:52:42 AM6/24/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
------------------------------+-------------------------------------
Reporter: Dan Strokirk | Owner: Alex Hill
Type: Bug | Status: assigned
Component: Forms | Version: 3.2

Severity: Normal | Resolution:
Keywords: JSONField | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
------------------------------+-------------------------------------

Comment (by Dan Strokirk):

New PR: https://github.com/django/django/pull/14558#issuecomment-867732503

--
Ticket URL: <https://code.djangoproject.com/ticket/32807#comment:5>

Django

unread,
Jun 24, 2021, 11:55:46 AM6/24/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
------------------------------+----------------------------------------
Reporter: Dan Strokirk | Owner: Dan Strokirk
Type: Bug | Status: assigned
Component: Forms | Version: 3.2

Severity: Normal | Resolution:
Keywords: JSONField | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+----------------------------------------
Changes (by Mariusz Felisiak):

* owner: Alex Hill => Dan Strokirk
* needs_better_patch: 1 => 0
* needs_tests: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/32807#comment:6>

Django

unread,
Jun 28, 2021, 5:03:59 AM6/28/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
-------------------------------------+-------------------------------------

Reporter: Dan Strokirk | Owner: Dan
| Strokirk
Type: Bug | Status: assigned
Component: Forms | Version: 3.2
Severity: Normal | Resolution:
Keywords: JSONField | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32807#comment:7>

Django

unread,
Jun 28, 2021, 5:27:22 AM6/28/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
-------------------------------------+-------------------------------------
Reporter: Dan Strokirk | Owner: Dan
| Strokirk
Type: Bug | Status: closed
Component: Forms | Version: 3.2
Severity: Normal | Resolution: fixed

Keywords: JSONField | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"f5ea9aa2f32c7ca9a1fdf793580fddba3daae1b9" f5ea9aa2]:
{{{
#!CommitTicketReference repository=""
revision="f5ea9aa2f32c7ca9a1fdf793580fddba3daae1b9"
Fixed #32807 -- Fixed JSONField crash when redisplaying None values.

Thanks to Alex Hill for the initial patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32807#comment:8>

Django

unread,
Dec 6, 2021, 4:59:38 AM12/6/21
to django-...@googlegroups.com
#32807: JSONField.bound_data raises TypeError when data is None
-------------------------------------+-------------------------------------
Reporter: Dan Strokirk | Owner: Dan
| Strokirk
Type: Bug | Status: closed
Component: Forms | Version: 3.2

Severity: Normal | Resolution: fixed
Keywords: JSONField | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Timothy Hobbs):

Hi, was this fixed already in the release Django 3.2.7? I'm getting this
backtrace on Django 3.2.7 when running admin smoke tests and the backtrace
doesn't touch my code at all, making it a bit tricky to debug:

{{{
======================================================================
ERROR: test_change_post (apps.aklub.tests.test_admin.AdminSmokeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/klub-v/venv/src/django-admin-smoke-
tests-2/django_admin_smoke_tests/tests.py", line 31, in test_deco
fn(self, model, model_admin)
File "/klub-v/venv/src/django-admin-smoke-
tests-2/django_admin_smoke_tests/tests.py", line 307, in test_change_post
response.render()
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/response.py", line 105, in render
self.content = self.rendered_content
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/response.py", line 83, in rendered_content
return template.render(context, self._request)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 170, in render
return self._render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/test/utils.py",
line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/test/utils.py",
line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/test/utils.py",
line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/test/utils.py",
line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/test/utils.py",
line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/test/utils.py",
line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/test/utils.py",
line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/defaulttags.py", line 211, in render
nodelist.append(node.render_annotated(context))
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/loader_tags.py", line 195, in render
return template.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 172, in render
return self._render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/test/utils.py",
line 100, in instrumented_test_render
return self.nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/defaulttags.py", line 211, in render
nodelist.append(node.render_annotated(context))
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/defaulttags.py", line 211, in render
nodelist.append(node.render_annotated(context))
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/defaulttags.py", line 312, in render
return nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-
packages/django/template/defaulttags.py", line 312, in render
return nodelist.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 938, in render
bit = node.render_annotated(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 905, in render_annotated
return self.render(context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 994, in render
return render_value_in_context(output, context)
File "/klub-v/venv/lib/python3.8/site-packages/django/template/base.py",
line 973, in render_value_in_context
value = str(value)
File "/klub-v/venv/lib/python3.8/site-packages/django/utils/html.py",
line 376, in <lambda>
klass.__str__ = lambda self: mark_safe(klass_str(self))
File "/klub-v/venv/lib/python3.8/site-
packages/django/forms/boundfield.py", line 34, in __str__
return self.as_widget()
File "/klub-v/venv/lib/python3.8/site-
packages/django/forms/boundfield.py", line 95, in as_widget
value=self.value(),
File "/klub-v/venv/lib/python3.8/site-
packages/django/forms/boundfield.py", line 130, in value
data = self.field.bound_data(self.data, data)
File "/klub-v/venv/lib/python3.8/site-packages/django/forms/fields.py",
line 1265, in bound_data
return json.loads(data, cls=self.decoder)
File "/usr/local/lib/python3.8/json/__init__.py", line 341, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '


TypeError: the JSON object must be str, bytes or bytearray, not NoneType
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32807#comment:9>

Reply all
Reply to author
Forward
0 new messages