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

Subclassing AbstractUserSocialAuth creates migration in social_django app. #496

Open
raratiru opened this issue Sep 4, 2023 · 1 comment

Comments

@raratiru
Copy link

raratiru commented Sep 4, 2023

Expected behaviour

Subclass AbstractUserSocialAuth in my app and create a migration in my app folder.

Actual behaviour

A migration is created in social_django/migrations folder.

  • schema is a local application with an abstract model to compare the behavior.
  • AbstractUserSocialAuth requires to override the user attribute in order to avoid related_name collision` so:
  • I override the slug attribute in BaseSlug to be in par:

What are the steps to reproduce this issue?

Input clear steps to reproduce the issue for a maintainer.

  1. Install social-app-django as per the docs.
  2. people is the app with the custom user model.

people/models.py:

from django.contrib.auth.models import AbstractUser
from django.contrib.auth import get_user_model
from django.db import models
from social_django.models import AbstractUserSocialAuth
from schema.models import BaseSlug


class User(AbstractUser):
    pass


class Test(BaseSlug):
    slug = models.IntegerField(
        primary_key=True, db_index=True, verbose_name="Slug"
    )


class Test2(AbstractUserSocialAuth):
    user = models.ForeignKey(
        get_user_model(), related_name="people_social_auth", on_delete=models.CASCADE
    )
  1. ./manage.py makemigrations

Any logs, error output, etc?

Result:

Migrations for 'people':
  people/migrations/0002_test.py
    - Create model Test
Migrations for 'social_django':
  .venv/lib/python3.11/site-packages/social_django/migrations/0016_test2.py
    - Create model Test2

Any other comments?

  • Why is that?
  • What will happen if social_django also creates a migration no. 16?

I need to encrypt uid field and I am not sure that creating a migration in social_django app helps. Is this intended?

My solution is to create AbstractuserSocialAuth from scratch.

@raratiru raratiru changed the title Subclassing AbstractUserSocialAuth creates migration i social_django app. Subclassing AbstractUserSocialAuth creates migration in social_django app. Sep 4, 2023
@raratiru
Copy link
Author

raratiru commented Sep 6, 2023

If this is intended, it would be nice to have the following methods to an InProjectMixin in order to avoid unnecessary code duplication.

@classmethod
def get_social_auth(cls, provider, uid):
try:
return cls.objects.select_related("user").get(provider=provider, uid=uid)
except cls.DoesNotExist:
return None
@classmethod
def username_max_length(cls):
username_field = cls.username_field()
field = cls.user_model()._meta.get_field(username_field)
return field.max_length
@classmethod
def user_model(cls):
return cls._meta.get_field("user").remote_field.model

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

No branches or pull requests

1 participant