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

AbstractUserSocialAuth and user field related_name #925

Closed
esistgut opened this issue May 11, 2016 · 4 comments
Closed

AbstractUserSocialAuth and user field related_name #925

esistgut opened this issue May 11, 2016 · 4 comments

Comments

@esistgut
Copy link

esistgut commented May 11, 2016

I am getting a problem with the user field of the AbstractUserSocialAuth: if I try to create an alternative UserSocialAuth inheriting AbstractUserSocialAuth the related_name of the user fields will clash because both will inherit the related_name from AbstractUserSocialAuth:

accounts.CustomUserSocialAuth.user: (fields.E304) Reverse accessor for 'CustomUserSocialAuth.user' clashes with reverse accessor for 'UserSocialAuth.user'.
        HINT: Add or change a related_name argument to the definition for 'CustomUserSocialAuth.user' or 'UserSocialAuth.user'.
accounts.CustomUserSocialAuth.user: (fields.E305) Reverse query name for 'CustomUserSocialAuth.user' clashes with reverse query name for 'UserSocialAuth.user'.
        HINT: Add or change a related_name argument to the definition for 'CustomUserSocialAuth.user' or 'UserSocialAuth.user'.
default.UserSocialAuth.user: (fields.E304) Reverse accessor for 'UserSocialAuth.user' clashes with reverse accessor for 'CustomUserSocialAuth.user'.
        HINT: Add or change a related_name argument to the definition for 'UserSocialAuth.user' or 'CustomUserSocialAuth.user'.
default.UserSocialAuth.user: (fields.E305) Reverse query name for 'UserSocialAuth.user' clashes with reverse query name for 'CustomUserSocialAuth.user'.
        HINT: Add or change a related_name argument to the definition for 'UserSocialAuth.user' or 'CustomUserSocialAuth.user'.

What is the expected way to override this class? As per Django's documentation the related_name should not be hardcoded in an abstract class, maybe I'm missing something, can you help?

@esistgut
Copy link
Author

Another question regarding https://github.com/omab/python-social-auth/blob/master/social/apps/django_app/default/models.py#L50

Why is the child class hardcoded in the parent abstract class?
Shouldn't this be:

except cls.DoesNotExist:

Like it is in the mixin which is the base for AbstractUserSocialAuth?

@omab
Copy link
Owner

omab commented Dec 27, 2016

I've created python-social-auth/social-app-django#7 to track the needed work to fix this (second issue, cls.DoesNotExists is already fixed).

@omab omab closed this as completed Dec 27, 2016
@omab
Copy link
Owner

omab commented Jan 1, 2017

The override should also override the user field and the corresponding related name to avoid the clash, I've removed the usage of .social_auth related field from the examples and the lib since it should't depend on such property due to overridable nature of it, Storage.user.get_social_auth_for_user(...) can be used for such means too, where Storage is the custom storage solution that overrides the built-in one.

@1nF0rmed
Copy link

Is there an alternative approach that is a bit more production-friendly?

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

No branches or pull requests

3 participants