Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#21087 closed Bug (wontfix)

"datatime" objects can not be JSON-serialized to be held in sessions

Reported by: epandurski@… Owned by: nobody
Component: Core (Serialization) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am using Django 1.6 beta 3.

In my view I try:

now = datetime.datetime.now(pytz.utc)
request.session['lstts'] = now

But I get the following error: http://dpaste.com/hold/1375033/

I presume the reason is the new serializer for session objects. I also presume that "datatime" objects must be supported, because they are quite useful and used.

Change History (3)

comment:1 by Aymeric Augustin, 11 years ago

The JSON format doesn't provide a type for dates/datetimes. We'll have to resort to a hack to support this use case.

comment:2 by Tim Graham, 11 years ago

Resolution: fixed
Status: newclosed

This was discussed quite a bit during the implementation, and the caveats of JSON serialization have been documented:

https://docs.djangoproject.com/en/dev/releases/1.6/#default-session-serialization-switched-to-json

https://docs.djangoproject.com/en/dev/topics/http/sessions/#session-serialization

You can continue to use the PickleSerializer if needed.

comment:3 by Tim Graham, 11 years ago

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