python-social-auth / social-app-django

Python Social Auth - Application - Django
BSD 3-Clause "New" or "Revised" License
2.03k stars 380 forks source link

Subclassing AbstractUserSocialAuth creates migration in social_django app. #496

Open raratiru opened 1 year ago

raratiru commented 1 year ago

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.

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?

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 commented 1 year ago

If this is intended, it would be nice to have the following methods to an InProjectMixin in order to avoid unnecessary code duplication. https://github.com/python-social-auth/social-app-django/blob/199435bce649b1fbcc48891bd98137332a84e2c5/social_django/models.py#L55-L70