Opened 6 years ago
Closed 5 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 , 6 years ago
| Summary: | xml serializing doesn't work with JSONField → xml serializing doesn't work with JSONField. |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Version: | 2.2 → master |
comment:2 by , 6 years ago
| Summary: | xml serializing doesn't work with JSONField. → XML serializer doesn't handle JSONFields. |
|---|
comment:3 by , 6 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:4 by , 6 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:6 by , 6 years ago
| Patch needs improvement: | set |
|---|
comment:7 by , 6 years ago
| Owner: | changed from to |
|---|---|
| Patch needs improvement: | unset |
comment:8 by , 5 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:9 by , 5 years ago
Note:
See TracTickets
for help on using tickets.
Thanks for the report. I was able to reproduce this issue.
Reproduced at a9179ab032cda80801e7f67ef20db5ee60989f21.