Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #45 -- AttributeError while resolving the user model in Django #46

Merged
merged 1 commit into from
Oct 4, 2013

Conversation

MarkusH
Copy link
Contributor

@MarkusH MarkusH commented Oct 4, 2013

Under some conditions UserSocialAuth._meta.get_field('user').rel.to does not return a Model class but a string of the form '<app_label>.<model_name>'. This results in an AttributeError in the Django admin.py which ultimately triggers an error in Django's RegexURLResolver. This is fixed by properly resolving the user model and return a class rather than a string.

ipdb> /home/markus/Coding/python-social-auth/social/apps/django_app/default/admin.py(5)<module>()
      4 
----> 5 from django.contrib import admin
      6 from social.apps.django_app.default.models import UserSocialAuth, Nonce, \

ipdb> n
> /home/markus/Coding/python-social-auth/social/apps/django_app/default/admin.py(6)<module>()
      5 from django.contrib import admin
----> 6 from social.apps.django_app.default.models import UserSocialAuth, Nonce, \
      7                                                   Association

ipdb> 
> /home/markus/Coding/python-social-auth/social/apps/django_app/default/admin.py(10)<module>()
      9 
---> 10 _User = UserSocialAuth.user_model()
     11 
> /home/markus/Coding/python-social-auth/social/apps/django_app/default/models.py(59)user_model()
     58 
---> 59     @classmethod
     60     def user_model(cls):

ipdb> n
> /home/markus/Coding/python-social-auth/social/apps/django_app/default/models.py(61)user_model()
     60     def user_model(cls):
---> 61         return UserSocialAuth._meta.get_field('user').rel.to
     62 

ipdb> UserSocialAuth._meta
<Options for UserSocialAuth>
ipdb> UserSocialAuth._meta.get_field('user')
<django.db.models.fields.related.ForeignKey: user>
ipdb> UserSocialAuth._meta.get_field('user').rel
<django.db.models.fields.related.ManyToOneRel object at 0x7f8d29848fd0>
ipdb> UserSocialAuth._meta.get_field('user').rel.to
'auth.BakeryUser'

Under some conditions ``UserSocialAuth._meta.get_field('user').rel.to`` does not return a Model class but a string of the form ``'<app_label>.<model_name>'``. This results in an AttributeError in the Django admin.py which ultimately triggers an error in Django's RegexURLResolver. This is fixed by properly resolving the user model and return a class rather than a string.
omab added a commit that referenced this pull request Oct 4, 2013
Fixes #45 -- AttributeError while resolving the user model in Django
@omab omab merged commit 9004e64 into omab:master Oct 4, 2013
@omab
Copy link
Owner

omab commented Oct 4, 2013

Thanks!

@MarkusH MarkusH deleted the fix-django-user-model branch October 4, 2013 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants