Django

Code

Ticket #5553 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

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

Reported by: pigletto Assigned to: nobody
Milestone: Component: Serialization
Version: SVN Keywords: json
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation:
Needs tests: Patch needs improvement:

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

json.diff (2.9 kB) - added by pigletto on 09/20/07 04:58:17.

Change History

09/20/07 04:58:17 changed by pigletto

  • attachment json.diff added.

09/22/07 08:21:54 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #5553 (JSON serializer imporperly serializes: datetime.datetime, datetime.time, float)




Change Properties
Action