#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 )
>>> 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.
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 , 4 years ago
Description: | modified (diff) |
---|
follow-up: 3 comment:2 by , 4 years ago
Component: | Forms → Database layer (models, ORM) |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Summary: | admin can't display Chinese normally when a JsonField contains Chinese → Admin doesn't display Chinese chars in JsonFields. |
Type: | Bug → New feature |
comment:3 by , 4 years ago
Resolution: | wontfix |
---|---|
Status: | closed → new |
Type: | New feature → Bug |
Replying to felixxm:
As far as I'm aware, we cannot use
ensure_ascii=False
by default because it requiresutf8mb4
encoding on MySQL, see #18392. It looks that you can use a customencoder
/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:4 by , 4 years ago
We just need to modify this line.https://github.com/django/django/blob/3d4ffd1ff0eb9343ee41de77caf6ae427b6e873c/django/forms/fields.py#L1261
Then I read the source code of django tests , and It seems that internationalization is not considered.(https://github.com/django/django/blob/3d4ffd1ff0eb9343ee41de77caf6ae427b6e873c/tests/forms_tests/field_tests/test_jsonfield.py#L29)
comment:5 by , 4 years ago
Component: | Database layer (models, ORM) → Forms |
---|
follow-up: 7 comment:6 by , 4 years ago
Severity: | Normal → Release blocker |
---|---|
Summary: | Admin doesn't display Chinese chars in JsonFields. → Admin doesn't display properly unicode chars in JSONFields. |
Triage Stage: | Unreviewed → Accepted |
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 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:8 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
follow-up: 11 comment:9 by , 4 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
You shouldn't mark your own ticket as RFC.
comment:11 by , 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.
As far as I'm aware, we cannot use
ensure_ascii=False
by default because it requiresutf8mb4
encoding on MySQL, see #18392. It looks that you can use a customencoder
/decoder
to make it works without changes in Django.