[Django] #31157: JSONField are not properly displayed in admin when they are readonly.

53 views
Skip to first unread message

Django

unread,
Jan 10, 2020, 9:58:46 AM1/10/20
to django-...@googlegroups.com
#31157: JSONField are not properly displayed in admin when they are readonly.
-----------------------------------------+----------------------------
Reporter: Gagaro | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.0
Severity: Normal | Keywords: admin json
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+----------------------------
JSONField values are displayed as dict when readonly in the admin.

For example, `{"foo": "bar"}` would be displayed as `{'foo': 'bar'}`,
which is not valid JSON.

I believe the fix would be to add a special case in
`django.contrib.admin.utils.display_for_field` to call the `prepare_value`
of the `JSONField` (not calling `json.dumps` directly to take care of the
`InvalidJSONInput` case).

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

Django

unread,
Jan 10, 2020, 12:35:47 PM1/10/20
to django-...@googlegroups.com
#31157: JSONField are not properly displayed in admin when they are readonly.
-------------------------------+------------------------------------

Reporter: Gagaro | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: admin json | Triage Stage: Accepted

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

* stage: Unreviewed => Accepted


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

Django

unread,
Jan 10, 2020, 10:29:25 PM1/10/20
to django-...@googlegroups.com
#31157: JSONField are not properly displayed in admin when they are readonly.
-------------------------------+------------------------------------
Reporter: Gagaro | Owner: dbxnr
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: admin json | Triage Stage: Accepted

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

* owner: nobody => dbxnr
* status: new => assigned


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

Django

unread,
Jan 12, 2020, 9:38:56 AM1/12/20
to django-...@googlegroups.com
#31157: JSONField are not properly displayed in admin when they are readonly.
-------------------------------+------------------------------------
Reporter: Gagaro | Owner: dbxnr
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: admin json | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by dbxnr):

* has_patch: 0 => 1


Comment:

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

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

Django

unread,
Jan 13, 2020, 12:48:17 AM1/13/20
to django-...@googlegroups.com
#31157: JSONField are not properly displayed in admin when they are readonly.
-------------------------------+------------------------------------
Reporter: Gagaro | Owner: dbxnr
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: admin json | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Simon Charette):

The proposed patch is problematic as the first version coupled
`contrib.postgres` with `.admin` and the current one is based off the type
name which is brittle and doesn't account for inheritance.

It might be worth waiting for #12990 to land before proceeding here as the
patch will be able to simply rely of `django.db.models.JSONField` instance
checks from that point.

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

Django

unread,
May 8, 2020, 4:27:11 AM5/8/20
to django-...@googlegroups.com
#31157: JSONField are not properly displayed in admin when they are readonly.
-------------------------------+------------------------------------
Reporter: Gagaro | Owner: dbxnr
Type: Bug | Status: assigned
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: admin json | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"675ce4dd35702ce353006611ba30799c0c4b015f" 675ce4d]:
{{{
#!CommitTicketReference repository=""
revision="675ce4dd35702ce353006611ba30799c0c4b015f"
Refs #31157 -- Added tests for display_for_field() with empty JSONField.
}}}

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

Django

unread,
May 8, 2020, 4:27:11 AM5/8/20
to django-...@googlegroups.com
#31157: JSONField are not properly displayed in admin when they are readonly.
-------------------------------+------------------------------------
Reporter: Gagaro | Owner: dbxnr
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: fixed
Keywords: admin json | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"fc0f7f6c152766c92a95c74a02cc6fab79440ed8" fc0f7f6c]:
{{{
#!CommitTicketReference repository=""
revision="fc0f7f6c152766c92a95c74a02cc6fab79440ed8"
Fixed #31157 -- Fixed displaying read-only JSONField values in admin.
}}}

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

Reply all
Reply to author
Forward
0 new messages