Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#32080 closed Bug (fixed)

Admin doesn't display properly unicode chars in JSONFields.

Reported by: ZhaoQi99 Owned by: ZhaoQi99
Component: Forms Version: 3.1
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: yes

Description (last modified by ZhaoQi99)

>>> import json
>>> print json.dumps('中国')
"\u4e2d\u56fd"

json.dumps use ASCII encoding by default when serializing Chinese.
So when we edit a JsonField which contains Chinese character in Django admin,it will appear in ASCII characters.

https://user-images.githubusercontent.com/25344334/95312376-6fa92b00-08c1-11eb-9b48-3c5e14683e9c.png
https://user-images.githubusercontent.com/25344334/95312742-e0504780-08c1-11eb-82af-116b8f2e158a.png

I have try to fix this this problem in https://github.com/adamchainz/django-mysql/pull/714.And it works prefectly.

Change History (14)

comment:1 Changed 21 months ago by ZhaoQi99

Description: modified (diff)

comment:2 Changed 21 months ago by Mariusz Felisiak

Component: FormsDatabase layer (models, ORM)
Resolution: wontfix
Status: newclosed
Summary: admin can't display Chinese normally when a JsonField contains ChineseAdmin doesn't display Chinese chars in JsonFields.
Type: BugNew feature

As far as I'm aware, we cannot use ensure_ascii=False by default because it requires utf8mb4 encoding on MySQL, see #18392. It looks that you can use a custom encoder/decoder to make it works without changes in Django.

comment:3 in reply to:  2 Changed 21 months ago by ZhaoQi99

Resolution: wontfix
Status: closednew
Type: New featureBug

Replying to felixxm:

As far as I'm aware, we cannot use ensure_ascii=False by default because it requires utf8mb4 encoding on MySQL, see #18392. It looks that you can use a custom encoder/decoder to make it works without changes in Django.

No, this function is only used in Django admin's display, so it will not influence any operation about MySQL writing and reading.
I just tested it using utf8 encoding on MySQL, and it works perfectly.
In my view, If we save non-ASCII characters in a JsonField ,such as emoij,chinese,Japanese....
And when we want to edit it in Django's admin, it is really not good if it displays in ASCII characters.
In order to fix this,we need to do many extra things...

comment:5 Changed 21 months ago by ZhaoQi99

Component: Database layer (models, ORM)Forms

comment:6 Changed 21 months ago by Mariusz Felisiak

Severity: NormalRelease blocker
Summary: Admin doesn't display Chinese chars in JsonFields.Admin doesn't display properly unicode chars in JSONFields.
Triage Stage: UnreviewedAccepted

No, this function is only used in Django admin's display, so it will not influence any operation about MySQL writing and reading.

Sorry I missed that. Good catch. Would you like to provide a patch?

comment:7 in reply to:  6 Changed 21 months ago by ZhaoQi99

Owner: changed from nobody to ZhaoQi99
Status: newassigned

Replying to felixxm:

Sorry I missed that. Good catch. Would you like to provide a patch?

Yep!

comment:8 Changed 21 months ago by ZhaoQi99

Triage Stage: AcceptedReady for checkin

comment:9 Changed 21 months ago by Mariusz Felisiak

Triage Stage: Ready for checkinAccepted

You shouldn't mark your own ticket as RFC.

comment:10 Changed 21 months ago by Mariusz Felisiak

Has patch: set

comment:11 in reply to:  9 Changed 21 months ago by ZhaoQi99

Replying to felixxm:

You shouldn't mark your own ticket as RFC.

I'm sorry.It's the first time I've used ticket system.

comment:12 Changed 21 months ago by Mariusz Felisiak

Triage Stage: AcceptedReady for checkin

np, now it's ready.

comment:13 Changed 21 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In de81676b:

Fixed #32080 -- Fixed displaying Unicode chars in forms.JSONField and read-only JSONField values in admin.

comment:14 Changed 21 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 8c403b17:

[3.1.x] Fixed #32080 -- Fixed displaying Unicode chars in forms.JSONField and read-only JSONField values in admin.

Backport of de81676b51e4dad510ef387c3ae625f9091fe57f from master

Note: See TracTickets for help on using tickets.
Back to Top