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

create_anonymous_user() breaks on migration rollback #770

Open
ZbigniewRA opened this issue Jan 30, 2022 · 0 comments
Open

create_anonymous_user() breaks on migration rollback #770

ZbigniewRA opened this issue Jan 30, 2022 · 0 comments

Comments

@ZbigniewRA
Copy link

post_migrate handler create_anonymous_user() breaks when a migration that adds a field to the User model is rolled back.

Bug is in this line:

User.objects.using(kwargs['using']).get(**lookup)

The problem is that get() tries to fetch all fields, but some of the fields no longer exist (as they were removed in a rollback).

A fix is to fetch the only field we know exists:

User.objects.using(kwargs['using']).filter(**lookup).only(User.USERNAME_FIELD).get()
akikoskinen added a commit to City-of-Helsinki/open-city-profile that referenced this issue Nov 30, 2022
Django-guardian supports giving Django's permissions to anonymous users.
This feature has an issue when a field is added or removed in the User
model: an exception gets thrown after the migration is run [1].

Open-city-profile doesn't currently use this feature. It can be disabled
by setting the `ANONYMOUS_USER_NAME` setting to `None` [2].

[1] django-guardian/django-guardian#770
[2] https://django-guardian.readthedocs.io/en/stable/configuration.html#anonymous-user-name
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