[Django] #33515: Adding ManyToMany field using setttings.AUTH_USER_MODEL creates unnecessary migrations

44 views
Skip to first unread message

Django

unread,
Feb 14, 2022, 8:52:29 PM2/14/22
to django-...@googlegroups.com
#33515: Adding ManyToMany field using setttings.AUTH_USER_MODEL creates unnecessary
migrations
-------------------------------------+-------------------------------------
Reporter: Chris Lee | Owner: nobody
Type: Bug | Status: new
Component: | Version: 4.0
Migrations | Keywords: M2M migration user
Severity: Normal | manytomany
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
If I create a custom user model that extends `AbstractUser` and then try
to add a `ManyToManyField` that references this custom User model, django
keeps making the same `AlterField` migration over and over again
unnecessarily. I've attached a Git repository that I used to reproduce
this issue with very simple code. You can see the two erroneous migrations
after the initial migration. If I use the built in user, there is no
issue. It seems to appear once I extend `AbstractUser`.

Git repository: https://github.com/SentientClee/django-bug-reproduction

Here is the `accounts` app `model.py` code.
{{{#!python
from django.conf import settings
from django.contrib.auth.models import AbstractUser
from django.db import models


class User(AbstractUser):
pass


class Test(models.Model):
members = models.ManyToManyField(settings.AUTH_USER_MODEL)
}}}

Here is one of the erroneous migrations. Notice it depends on
`0002_alter_test_members` which is an erroneous migrations file that looks
just like this one.
{{{#!python
# Generated by Django 4.0.2 on 2022-02-15 01:33

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0002_alter_test_members'),
]

operations = [
migrations.AlterField(
model_name='test',
name='members',
field=models.ManyToManyField(to=settings.AUTH_USER_MODEL),
),
]
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33515>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 14, 2022, 8:53:10 PM2/14/22
to django-...@googlegroups.com
#33515: Adding ManyToMany field using custom User model (AbstractUser) creates
unnecessary migrations
-------------------------------------+-------------------------------------
Reporter: SentientClee | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: M2M migration user | Triage Stage:
manytomany | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/33515#comment:1>

Django

unread,
Feb 15, 2022, 12:52:40 AM2/15/22
to django-...@googlegroups.com
#33515: ManyToManyField to lowercased swappable setting causes generating infinite
migrations.

-------------------------------------+-------------------------------------
Reporter: Chris Lee | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: M2M migration user | Triage Stage: Accepted
manytomany |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Simon Charette, David Wobrock (added)
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Thanks for the report!

Lowercased `AUTH_USER_MODEL = 'accounts.user'` is crucial to reproduce
this issue.

Regression in 43289707809c814a70f0db38ca4f82f35f43dbfd.

--
Ticket URL: <https://code.djangoproject.com/ticket/33515#comment:2>

Django

unread,
Feb 16, 2022, 2:59:51 AM2/16/22
to django-...@googlegroups.com
#33515: ManyToManyField to lowercased swappable setting causes generating infinite
migrations.
-------------------------------------+-------------------------------------
Reporter: Chris Lee | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned

Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: M2M migration user | Triage Stage: Accepted
manytomany |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* owner: nobody => Mariusz Felisiak
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33515#comment:3>

Django

unread,
Feb 16, 2022, 3:42:55 AM2/16/22
to django-...@googlegroups.com
#33515: ManyToManyField to lowercased swappable setting causes generating infinite
migrations.
-------------------------------------+-------------------------------------

Reporter: Chris Lee | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: M2M migration user | Triage Stage: Accepted
manytomany |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/15433 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/33515#comment:4>

Django

unread,
Feb 16, 2022, 3:09:52 PM2/16/22
to django-...@googlegroups.com
#33515: ManyToManyField to lowercased swappable setting causes generating infinite
migrations.
-------------------------------------+-------------------------------------

Reporter: Chris Lee | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution: fixed

Keywords: M2M migration user | Triage Stage: Accepted
manytomany |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"1e2e1be02bdf0fe4add0d0279dbca1d74ae28ad7" 1e2e1be]:
{{{
#!CommitTicketReference repository=""
revision="1e2e1be02bdf0fe4add0d0279dbca1d74ae28ad7"
Fixed #33515 -- Prevented recreation of migration for ManyToManyField to
lowercased swappable setting.

Thanks Chris Lee for the report.

Regression in 43289707809c814a70f0db38ca4f82f35f43dbfd.

Refs #23916.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33515#comment:5>

Django

unread,
Feb 16, 2022, 3:11:14 PM2/16/22
to django-...@googlegroups.com
#33515: ManyToManyField to lowercased swappable setting causes generating infinite
migrations.
-------------------------------------+-------------------------------------

Reporter: Chris Lee | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution: fixed
Keywords: M2M migration user | Triage Stage: Accepted
manytomany |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"760b7e7f4f62eafdc79a2188d2a7739abaa6ca8b" 760b7e7f]:
{{{
#!CommitTicketReference repository=""
revision="760b7e7f4f62eafdc79a2188d2a7739abaa6ca8b"
[4.0.x] Fixed #33515 -- Prevented recreation of migration for


ManyToManyField to lowercased swappable setting.

Thanks Chris Lee for the report.

Regression in 43289707809c814a70f0db38ca4f82f35f43dbfd.

Refs #23916.
Backport of 1e2e1be02bdf0fe4add0d0279dbca1d74ae28ad7 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33515#comment:6>

Reply all
Reply to author
Forward
0 new messages