Opened 17 years ago

Closed 17 years ago

#5553 closed (fixed)

JSON serializer imporperly serializes: datetime.datetime, datetime.time, float

Reported by: Maciej Wiśniowski Owned by: nobody
Component: Core (Serialization) Version: dev
Severity: Keywords: json
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This bug was introduced after commiting patch for this ticket: http://code.djangoproject.com/ticket/4714
Original patch I've written was changed by commiter and this introduced some issues.

Problem is that now serializers/python.py uses smart_unicode(... , strings_only=True).
Unfortunatelly smart_unicode only recogizes None, int and long as not strings.
Because of this, datetime objects (as well as floats) are converted to strings.
This causes that serializers/json.py -> DjangoJSONEncoder is useless.

My, original implementation from #4714, uses function 'str_to_unicode' that converts only
instances of basestring to unicode - so it works properly.

I'm not sure why it was changed to 'smart_unicode', but if 'smart_unicode' should be used then
'force_unicodes detection of strings has to be changed.
Problem is with datetime.datetime, datetime.time, float and possibly Decimal.

I've attached a patch with tests.

Attachments (1)

json.diff (2.9 KB ) - added by Maciej Wiśniowski 17 years ago.

Download all attachments as: .zip

Change History (2)

by Maciej Wiśniowski, 17 years ago

Attachment: json.diff added

comment:1 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: newclosed

(In [6406]) Fixed #5553 -- Fixed a serialization problem with datetime and time objects. Thanks to pigletto for the patch.

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