Opened 4 years ago

Closed 4 years ago

Last modified 4 years 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 by ZhaoQi99, 4 years ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 4 years ago

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.

in reply to:  2 comment:3 by ZhaoQi99, 4 years ago

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 by ZhaoQi99, 4 years ago

Component: Database layer (models, ORM)Forms

comment:6 by Mariusz Felisiak, 4 years ago

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?

in reply to:  6 comment:7 by ZhaoQi99, 4 years ago

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 by ZhaoQi99, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Mariusz Felisiak, 4 years ago

Triage Stage: Ready for checkinAccepted

You shouldn't mark your own ticket as RFC.

comment:10 by Mariusz Felisiak, 4 years ago

Has patch: set

in reply to:  9 comment:11 by ZhaoQi99, 4 years ago

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 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

np, now it's ready.

comment:13 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In de81676b:

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

comment:14 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

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