Opened 5 years ago

Closed 4 years ago

#30583 closed Bug (fixed)

XML serializer doesn't handle JSONFields.

Reported by: Ustinov Sergey Owned by: Hasan Ramezani
Component: Core (Serialization) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

Change History (10)

comment:1 by Mariusz Felisiak, 5 years ago

Summary: xml serializing doesn't work with JSONFieldxml serializing doesn't work with JSONField.
Triage Stage: UnreviewedAccepted
Version: 2.2master

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

Reproduced at a9179ab032cda80801e7f67ef20db5ee60989f21.

comment:2 by Mariusz Felisiak, 5 years ago

Summary: xml serializing doesn't work with JSONField.XML serializer doesn't handle JSONFields.

comment:3 by Chason Chaffin, 5 years ago

Owner: changed from nobody to Chason Chaffin
Status: newassigned

comment:4 by Chason Chaffin, 5 years ago

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?

comment:5 by Mariusz Felisiak, 5 years ago

Has patch: set

comment:6 by Mariusz Felisiak, 5 years ago

Patch needs improvement: set

comment:7 by Hasan Ramezani, 5 years ago

Owner: changed from Chason Chaffin to Hasan Ramezani
Patch needs improvement: unset
Last edited 5 years ago by Mariusz Felisiak (previous) (diff)

comment:8 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Mariusz Felisiak, 4 years ago

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 PR9801, PR9809, and PR11538.

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

Resolution: fixed
Status: assignedclosed

In 47651ead:

Fixed #30583 -- Fixed handling JSONFields in XML serializer.

Co-authored-by: Chason Chaffin <chason@…>

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