Opened 8 years ago

Closed 8 years ago

#5553 closed (fixed)

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

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


This bug was introduced after commiting patch for this ticket:
Original patch I've written was changed by commiter and this introduced some issues.

Problem is that now serializers/ 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/ -> 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 pigletto 8 years ago.

Download all attachments as: .zip

Change History (2)

Changed 8 years ago by pigletto

comment:1 Changed 8 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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