#26949 closed Bug (fixed)
Disabled forms.JSONField crashes with TypeError
Reported by: | Tim Graham | Owned by: | Olexander Yermakov |
---|---|---|---|
Component: | contrib.postgres | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The fix for #25532 is partially reverted to fix the regression in #26917 but this means the following test fails with TypeError: the JSON object must be str, not 'list'.
:
def test_formfield_disabled(self): class JsonForm(Form): name = CharField() jfield = forms.JSONField(disabled=True) form = JsonForm({'name': 'xyz', 'jfield': '["bar"]'}, initial={'jfield': ['foo']}) self.assertIn('["foo"]</textarea>', form.as_p())
Attachments (1)
Change History (10)
comment:1 by , 8 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
by , 8 years ago
Attachment: | 0001-Fix-disabled-forms.JSONField-crash-with-TypeError.patch added |
---|
comment:2 by , 8 years ago
Has patch: | set |
---|
Looks okay to me. I added that fix to my PR for the other ticket. Thanks!
comment:4 by , 8 years ago
Not needed since the committer will backport any commits as needed. I think I'll just backport to 1.10 only since 1.9.x will be in security fix only mode after the 1.10 release next week.
Note:
See TracTickets
for help on using tickets.
As I see the problem with previous fix was because assumption that initial values are already cleaned is wrong. I added these lines to omit
json.loads()
for disable field. But I think that's the obvious fix, means there are downsides here if it's not been done before, so I'm not sure about it. Could you, please, advice what could be wrong with this approach? Thanks!