Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

The django_util session data does not work with Django 1.10 #594

Closed
huwshimi opened this issue Aug 9, 2016 · 8 comments
Closed

The django_util session data does not work with Django 1.10 #594

huwshimi opened this issue Aug 9, 2016 · 8 comments
Labels

Comments

@huwshimi
Copy link

huwshimi commented Aug 9, 2016

The session serialiser with Django 1.10 does not support picked data, like that attached to the session here: https://github.com/google/oauth2client/blob/master/oauth2client/contrib/django_util/views.py#L74

This is the error received:

Traceback (most recent call last):
  File "/home/user/project/env/lib/python3.5/site-packages/django/core/handlers/base.py", line 131, in get_response
    response = middleware_method(request, response)
  File "/home/user/project/env/lib/python3.5/site-packages/opbeat/utils/wrapt/wrappers.py", line 562, in __call__
    args, kwargs)
  File "/home/user/project/env/lib/python3.5/site-packages/opbeat/contrib/django/middleware/__init__.py", line 86, in process_response_wrapper
    response = wrapped(*args, **kwargs)
  File "/home/user/project/env/lib/python3.5/site-packages/django/contrib/sessions/middleware.py", line 58, in process_response
    request.session.save()
  File "/home/user/project/env/lib/python3.5/site-packages/django/contrib/sessions/backends/db.py", line 83, in save
    obj = self.create_model_instance(data)
  File "/home/user/project/env/lib/python3.5/site-packages/django/contrib/sessions/backends/db.py", line 69, in create_model_instance
    session_data=self.encode(data),
  File "/home/user/project/env/lib/python3.5/site-packages/django/contrib/sessions/backends/base.py", line 98, in encode
    serialized = self.serializer().dumps(session_dict)
  File "/home/user/project/env/lib/python3.5/site-packages/django/core/signing.py", line 93, in dumps
    return json.dumps(obj, separators=(',', ':')).encode('latin-1')
  File "/usr/lib/python3.5/json/__init__.py", line 237, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.5/json/encoder.py", line 198, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.5/json/encoder.py", line 256, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.5/json/encoder.py", line 179, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'\x80\x03coauth2client.client\nOAuth2WebServerFlow\nq\x00)\x81q\x01}q\x02(X\n\x00\x00\x00revoke_uriq\x03X+\x00\x00\x00[...scrubbed]' is not JSON serializable

Switching the session serialiser to PickleSerializer resolves the issue, but is not recommended due to security concerns.

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

More info can be found at: https://docs.djangoproject.com/en/1.10/topics/http/sessions/#session-serialization

@waprin
Copy link
Contributor

waprin commented Aug 9, 2016

Acknowledged.

@waprin
Copy link
Contributor

waprin commented Aug 10, 2016

@huwshimi , I'm having trouble reproducing this. I just ran it with Python 3.5.2 and Django 1.10.0 and it works fine for me.

The docs say that by default the serializer uses JSON. So I'm wondering why I am not reproducing this issue. I can keep looking into it, but any hints as to something I might be doing?

(django3) waprin-macbookpro:google_user waprin$ python
Python 3.5.2 (default, Aug 10 2016, 16:26:31) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 10, 0, 'final', 1)

@waprin
Copy link
Contributor

waprin commented Aug 10, 2016

I am wondering if it's something about that specific Flow...

@huwshimi
Copy link
Author

@waprin Thanks for taking a look. It could well be something to do with my project setup (this is an old project that has been upgraded to Django 1.10).

It could even be the data I'm passing in. If I figure out what it is, I'll add the details here.

@waprin
Copy link
Contributor

waprin commented Aug 11, 2016

Just out of curiosity what database are you using?

@waprin
Copy link
Contributor

waprin commented Aug 11, 2016

Never mind, able to reproduce it, was using localhost but actual server repros it, will work on it now.

@waprin
Copy link
Contributor

waprin commented Aug 15, 2016

@huwshimi please re-open if #614 does not fix your problem.

@waprin waprin closed this as completed Aug 15, 2016
@huwshimi
Copy link
Author

@waprin Thanks heaps, I'll give it a go!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants