#21404 closed Cleanup/optimization (fixed)
session.set_expiry() causes a TypeError when using JSONSerializer
Reported by: | René Puls | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
I am using django.contrib.sessions.backends.cached_db as the SESSION_ENGINE and django.contrib.sessions.serializers.JSONSerializer as the SESSION_SERIALIZER.
Setting a session expiration date using session.set_expiry() results in a TypeError when the session is saved:
Traceback: File "/Users/pwr/Library/Python/2.7/lib/python/site-packages/django/core/handlers/base.py" in get_response 201. response = middleware_method(request, response) File "/Users/pwr/Library/Python/2.7/lib/python/site-packages/django/contrib/sessions/middleware.py" in process_response 38. request.session.save() File "/Users/pwr/Library/Python/2.7/lib/python/site-packages/django/contrib/sessions/backends/cached_db.py" in save 62. super(SessionStore, self).save(must_create) File "/Users/pwr/Library/Python/2.7/lib/python/site-packages/django/contrib/sessions/backends/db.py" in save 57. session_data=self.encode(self._get_session(no_load=must_create)), File "/Users/pwr/Library/Python/2.7/lib/python/site-packages/django/contrib/sessions/backends/base.py" in encode 87. serialized = self.serializer().dumps(session_dict) File "/Users/pwr/Library/Python/2.7/lib/python/site-packages/django/core/signing.py" in dumps 88. return json.dumps(obj, separators=(',', ':')).encode('latin-1') File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py" in dumps 250. sort_keys=sort_keys, **kw).encode(obj) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py" in encode 207. chunks = self.iterencode(o, _one_shot=True) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py" in iterencode 270. return _iterencode(o, 0) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/encoder.py" in default 184. raise TypeError(repr(o) + " is not JSON serializable") Exception Type: TypeError at /users/login/ Exception Value: datetime.datetime(2013, 11, 9, 5, 0, tzinfo=<DstTzInfo 'Europe/Berlin' CET+1:00:00 STD>) is not JSON serializable
The documentation already notes that JSONSerializer cannot handle datetime values, which is working as intended according to #21124. The documentation for set_expiry also notes that "datetime and timedelta values are only serializable if you are using the PickleSerializer".
If this is indeed intentional, I suggest that the 1.6 release notes should at least mention that session expiration times can no longer be set in the default configuration.
Attachments (1)
Change History (7)
comment:1 by , 11 years ago
Component: | contrib.sessions → Documentation |
---|---|
Easy pickings: | set |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:2 by , 11 years ago
I can confirm that this seems like a relevant issue - there should be at least clear warning about a possibility of such errors coming up just from using default settings and methods.
by , 11 years ago
Attachment: | 21404.diff added |
---|
comment:3 by , 11 years ago
Has patch: | set |
---|
Attached is a proposed patch. Please let me know if you would add anything else.
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Accepting as a documentation addition.