[Django] #30583: xml serializing doesn't work with JSONField

14 views
Skip to first unread message

Django

unread,
Jun 21, 2019, 8:42:40 AM6/21/19
to django-...@googlegroups.com
#30583: xml serializing doesn't work with JSONField
------------------------------------------------+------------------------
Reporter: ustnv | Owner: nobody
Type: Bug | Status: new
Component: Core (Serialization) | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
I have code:

{{{
data = serializers.serialize("xml", queryset, fields=fields)
}}}

if I choose specific fields, which are not JSONField, it is ok. But if I
choose field, which is JSONField, I receive error
{{{
File "/Users/ustnv/PycharmProjects/fpg_nko/venv/lib/python3.6/site-
packages/django/core/serializers/__init__.py", line 128, in serialize
s.serialize(queryset, **options)
File "/Users/ustnv/PycharmProjects/fpg_nko/venv/lib/python3.6/site-
packages/django/core/serializers/base.py", line 107, in serialize
self.handle_field(obj, field)
File "/Users/ustnv/PycharmProjects/fpg_nko/venv/lib/python3.6/site-
packages/django/core/serializers/xml_serializer.py", line 79, in
handle_field
self.xml.characters(field.value_to_string(obj))
File "/Users/ustnv/PycharmProjects/fpg_nko/venv/lib/python3.6/site-
packages/django/utils/xmlutils.py", line 25, in characters
if content and re.search(r'[\x00-\x08\x0B-\x0C\x0E-\x1F]', content):
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py",
line 182, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object
}}}

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

Django

unread,
Jun 21, 2019, 9:36:38 AM6/21/19
to django-...@googlegroups.com
#30583: xml serializing doesn't work with JSONField.
--------------------------------------+------------------------------------
Reporter: Ustinov Sergey | Owner: nobody
Type: Bug | Status: new
Component: Core (Serialization) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

* version: 2.2 => master
* stage: Unreviewed => Accepted


Comment:

Thanks for the report. I was able to reproduce this issue.


Reproduced at a9179ab032cda80801e7f67ef20db5ee60989f21.

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

Django

unread,
Jun 21, 2019, 9:37:08 AM6/21/19
to django-...@googlegroups.com
#30583: XML serializer doesn't handle JSONFields.
--------------------------------------+------------------------------------
Reporter: Ustinov Sergey | Owner: nobody
Type: Bug | Status: new

Component: Core (Serialization) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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

Django

unread,
Jul 3, 2019, 11:50:09 AM7/3/19
to django-...@googlegroups.com
#30583: XML serializer doesn't handle JSONFields.
-------------------------------------+-------------------------------------
Reporter: Ustinov Sergey | Owner: Chason
| Chaffin
Type: Bug | Status: assigned
Component: Core | Version: master
(Serialization) |

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chason Chaffin):

* owner: nobody => Chason Chaffin
* status: new => assigned


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

Django

unread,
Jul 3, 2019, 8:59:06 PM7/3/19
to django-...@googlegroups.com
#30583: XML serializer doesn't handle JSONFields.
-------------------------------------+-------------------------------------
Reporter: Ustinov Sergey | Owner: Chason
| Chaffin
Type: Bug | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chason Chaffin):

How *should* JSONField serialize into XML? Should it be serialized first
into JSON then inserted into the node as a string? Should the Python data
structure just be put as a string into the node? Something more
complicated?

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

Django

unread,
Jul 4, 2019, 3:06:24 AM7/4/19
to django-...@googlegroups.com
#30583: XML serializer doesn't handle JSONFields.
-------------------------------------+-------------------------------------
Reporter: Ustinov Sergey | Owner: Chason
| Chaffin
Type: Bug | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

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

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

Django

unread,
Jul 18, 2019, 8:43:01 AM7/18/19
to django-...@googlegroups.com
#30583: XML serializer doesn't handle JSONFields.
-------------------------------------+-------------------------------------
Reporter: Ustinov Sergey | Owner: Chason
| Chaffin
Type: Bug | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


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

Django

unread,
Mar 23, 2020, 2:56:36 PM3/23/20
to django-...@googlegroups.com
#30583: XML serializer doesn't handle JSONFields.
-------------------------------------+-------------------------------------
Reporter: Ustinov Sergey | Owner: Hasan
| Ramezani

Type: Bug | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* owner: Chason Chaffin => Hasan Ramezani
* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/30583#comment:7>

Django

unread,
Jun 17, 2020, 5:14:01 AM6/17/20
to django-...@googlegroups.com
#30583: XML serializer doesn't handle JSONFields.
-------------------------------------+-------------------------------------
Reporter: Ustinov Sergey | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/30583#comment:8>

Django

unread,
Jun 17, 2020, 5:19:16 AM6/17/20
to django-...@googlegroups.com
#30583: XML serializer doesn't handle JSONFields.
-------------------------------------+-------------------------------------
Reporter: Ustinov Sergey | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

Comment (by felixxm):

As far as I'm concerned, it's not feasible to fix this by changing
`to_python()` and `value_to_string()` for `JSONField`, see discussions in
[https://github.com/django/django/pull/9801 PR9801],
[https://github.com/django/django/pull/9809 PR9809], and
[https://github.com/django/django/pull/11538 PR11538].

--
Ticket URL: <https://code.djangoproject.com/ticket/30583#comment:9>

Django

unread,
Jun 17, 2020, 5:55:01 AM6/17/20
to django-...@googlegroups.com
#30583: XML serializer doesn't handle JSONFields.
-------------------------------------+-------------------------------------
Reporter: Ustinov Sergey | Owner: Hasan
| Ramezani
Type: Bug | Status: closed

Component: Core | Version: master
(Serialization) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
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:"47651eadb8ca7aacddad41da4df64fd2af11faae" 47651ead]:
{{{
#!CommitTicketReference repository=""
revision="47651eadb8ca7aacddad41da4df64fd2af11faae"
Fixed #30583 -- Fixed handling JSONFields in XML serializer.

Co-authored-by: Chason Chaffin <cha...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30583#comment:10>

Reply all
Reply to author
Forward
0 new messages