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

Error with django-allauth if User model doesn't explicitly list objects = UserManager() as Manager #178

Open
Raxev opened this issue Aug 25, 2022 · 0 comments

Comments

@Raxev
Copy link

Raxev commented Aug 25, 2022

Python Version

3.9

Django Version

4.0.7

Package Version

1.3.0

Description

Hello, first of all, thank you for maintaining this package.

I found an error related to django-allauth after running the migrations generated after installing django-auto-prefetch.

The following is the error I got, which was preventing users from logging in.

image

After some digging I noticed that django-auto-prefetch changed the manager for the User Model from UserManager() to Manager(), which does not have the attribute get_by_natural_key

migrations.AlterModelManagers(
            name='user',
            managers=[
                ('objects', django.db.models.manager.Manager()),
                ('prefetch_manager', django.db.models.manager.Manager()),
            ],
        ),

To resolve this issue I had to explicitly add UserManager() as the manager for my User model as follows:

class User(auto_prefetch.Model, AbstractUser):
    """Represents a User's account."""
    objects = UserManager()
    ...

This change allowed the next migration files to be generated the way they were supposed to:

migrations.AlterModelManagers(
            name='user',
            managers=[
                ('objects', django.contrib.auth.models.UserManager()),
                ('prefetch_manager', django.db.models.manager.Manager()),
            ],
        ),

I think it would be helpful to add some sort of note letting others know how this might affect their User models.

Thank you!

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

1 participant