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

Django 1.10 removed `_meta.get_all_field_names()` #976

Closed nick-merrill closed 7 years ago

nick-merrill commented 8 years ago

Simply go to http://localhost:8000/admin/default/usersocialauth/ to trigger the error relating to the fact that Django 1.9 deprecated and then removed in 1.10 many _meta functions as part of the "formalization of the Model._meta api". [Django Reference]

This includes _User._meta.get_all_field_names().

nick-merrill commented 8 years ago

The following monkey patch should fix the issue in the short term:

# Monkey patch for Python Social Auth as per
# https://docs.djangoproject.com/en/1.9/ref/models/meta/#migrating-from-the-old-api
def get_all_field_names():
    from itertools import chain
    return list(set(chain.from_iterable(
        (field.name, field.attname) if hasattr(field, 'attname') else (field.name,)
        for field in User._meta.get_fields()
        # For complete backwards compatibility, you may want to exclude
        # GenericForeignKey from the results.
        if not (field.many_to_one and field.related_model is None)
    )))

User._meta.get_all_field_names = get_all_field_names
dogukankotan commented 8 years ago

instead of using all_names = _User._meta.get_all_field_names() use all_names = [f.name for f in _User._meta.get_fields()]

dogukankotan commented 8 years ago

Ha, I see the updates on admin.py. Please update pip for other Django 1.10.x users

omab commented 7 years ago

A fix for this was already merged into social-app-django.