omab / python-social-auth

Social auth made simple
http://psa.matiasaguirre.net
BSD 3-Clause "New" or "Revised" License
2.83k stars 1.09k forks source link

Custom JSONField does not work as expected #952

Closed EvaSDK closed 7 years ago

EvaSDK commented 8 years ago

Which makes it impossible to access extra_data since it is not unserialized.

I had to apply this workaround https://github.com/Linkuist/linkuist/commit/12716355286382c791f4b7f820b9ac3f9a008d62 in an old django 1.6 based project to get through strange AttributeError: 'unicode' object has no attribute 'get' or TypeError: string indices must be integers errors.

seroy commented 8 years ago

To run python-social-auth >= 0.2.15 on Django < 1.8, can use this mokey patch (past it in the end of settings.py):

def monkey_patch_socialauth_JSONField():
    from django.db import models
    from social.apps.django_app.default.fields import JSONField
    from social.apps.django_app.default.models import AbstractUserSocialAuth

    class PatchedJSONField(JSONField):
        __metaclass__ = models.SubfieldBase

    AbstractUserSocialAuth.add_to_class('extra_data', PatchedJSONField())

monkey_patch_socialauth_JSONField():