#32807 closed Bug (fixed)
JSONField.bound_data raises TypeError when data is None
Description ¶
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
Change History (9)
comment:1 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 4 years ago
comment:3 by , 4 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
comment:5 by , 4 years ago
comment:6 by , 4 years ago
Needs tests: | unset |
---|---|
Owner: | changed from | to
Patch needs improvement: | unset |
comment:7 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:9 by , 3 years ago
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
Note:
See TracTickets
for help on using tickets.
Regression in db19619545dd99a1d2502c72974d79eca33acff7.