[Django] #32367: Problems with 3.2 alpha - primary keys

11 views
Skip to first unread message

Django

unread,
Jan 19, 2021, 9:54:01 AM1/19/21
to django-...@googlegroups.com
#32367: Problems with 3.2 alpha - primary keys
-----------------------------------------+------------------------
Reporter: אורי | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
I have models which inherit from other models, and they should inherit the
primary key. This works fine with Django 3.1. However, if I install Django
3.2 alpha, when I run `make_migrations` I get the following error
messages:

{{{
System check identified some issues:

WARNINGS:
accounts.ReservedUsername: (models.W042) Auto-created primary key used
when not defining a primary key type, by default
'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
SpeedyCoreAccountsConfig.default_auto_field attribute to point to a
subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
accounts.User: (models.W042) Auto-created primary key used when not
defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
SpeedyCoreAccountsConfig.default_auto_field attribute to point to a
subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
blocks.Block: (models.W042) Auto-created primary key used when not
defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
AppConfig.default_auto_field attribute to point to a subclass of
AutoField, e.g. 'django.db.models.BigAutoField'.
contact_by_form.Feedback: (models.W042) Auto-created primary key used when
not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
SpeedyCoreContactByFormConfig.default_auto_field attribute to point to a
subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
core_messages.ReadMark: (models.W042) Auto-created primary key used when
not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
SpeedyCoreMessagesConfig.default_auto_field attribute to point to a
subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
friendship.Block: (models.W042) Auto-created primary key used when not
defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
AppConfig.default_auto_field attribute to point to a subclass of
AutoField, e.g. 'django.db.models.BigAutoField'.
friendship.Follow: (models.W042) Auto-created primary key used when not
defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
AppConfig.default_auto_field attribute to point to a subclass of
AutoField, e.g. 'django.db.models.BigAutoField'.
friendship.Friend: (models.W042) Auto-created primary key used when not
defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
AppConfig.default_auto_field attribute to point to a subclass of
AutoField, e.g. 'django.db.models.BigAutoField'.
friendship.FriendshipRequest: (models.W042) Auto-created primary key used
when not defining a primary key type, by default
'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
AppConfig.default_auto_field attribute to point to a subclass of
AutoField, e.g. 'django.db.models.BigAutoField'.
likes.UserLike: (models.W042) Auto-created primary key used when not
defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
AppConfig.default_auto_field attribute to point to a subclass of
AutoField, e.g. 'django.db.models.BigAutoField'.
uploads.Image: (models.W042) Auto-created primary key used when not
defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the
AppConfig.default_auto_field attribute to point to a subclass of
AutoField, e.g. 'django.db.models.BigAutoField'.
}}}

These models should not use auto-created primary keys! I already defined
the primary key in the ancestor of the model. For example class `Entity`
which class `User` inherits from. It looks to me like a bug in Django 3.2
alpha.

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

Django

unread,
Jan 19, 2021, 10:30:32 AM1/19/21
to django-...@googlegroups.com
#32367: Problems with 3.2 alpha - primary keys
-------------------------------+--------------------------------------

Reporter: אורי | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Simon Charette):

Hello Uri, thanks for testing out the alpha and the report.

> These models should not use auto-created primary keys! I already defined
the primary key in the ancestor of the model. For example class Entity
which class User inherits from. It looks to me like a bug in Django 3.2
alpha.

Could you provide a minimal project with a set of models to reproduce the
issue. I tried the following but couldn't reproduce

{{{#!python
from django.db import models

class Entity(models.Model):
id = models.AutoField(primary_key=True)

class User(models.Model):
pass
}}}

Also neither the `User` or `Entity` models are mentioned in your check
failures above.

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

Django

unread,
Jan 19, 2021, 11:02:42 AM1/19/21
to django-...@googlegroups.com
#32367: Problems with 3.2 alpha - primary keys
-------------------------------+--------------------------------------

Reporter: אורי | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by אורי):

Replying to [comment:1 Simon Charette]:


> Hello Uri, thanks for testing out the alpha and the report.
>

> > These models should not use auto-created primary keys! I already
defined the primary key in the ancestor of the model. For example class
Entity which class User inherits from. It looks to me like a bug in Django
3.2 alpha.
>

> Could you provide a minimal project with a set of models to reproduce
the issue. I tried the following but couldn't reproduce
>
> {{{#!python
> from django.db import models
>
> class Entity(models.Model):
> id = models.AutoField(primary_key=True)
>

> class User(Entity):


> pass
> }}}
>
> Also neither the `User` or `Entity` models are mentioned in your check
failures above.


Hi Simon,

Notice that `accounts.User` above is class `User` in the `accounts` app.
I'm not sure if I can provide a minimal project as you requested, but you
can see my code on GitHub. For example the models of the `accounts` app
are here:

https://github.com/speedy-net/speedy-
net/blob/master/speedy/core/accounts/models.py

(Search for "`class Entity`" and "`class User`". The `id =
SmallUDIDField()` field in class `Entity` is the primary key. It also
works for getting a `User` model by `User.objects.get(pk=...)`.

Also same is for `class ReservedUsername` above, which is a much more
simpler model than `class User`.

The definition of `SmallUDIDField` above (the primary key field) is on
https://github.com/speedy-net/speedy-
net/blob/master/speedy/core/base/fields.py .

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

Django

unread,
Jan 20, 2021, 2:32:43 AM1/20/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

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

* severity: Normal => Release blocker
* cc: Tom Forbes (added)
* component: Uncategorized => Database layer (models, ORM)
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

Thanks for the report.

Reproduced at bbd18943c6c00fb1386ecaaf6771a54f780ebf62.
Bug in b5e12d490af3debca8c55ab3c1698189fdedbbdb.

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

Django

unread,
Jan 20, 2021, 2:32:57 AM1/20/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "tests-32367.diff" added.

Regression test.

Django

unread,
Jan 20, 2021, 2:33:51 AM1/20/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* Attachment "tests-32367.diff" added.

Regression test.

--

Django

unread,
Jan 20, 2021, 5:38:53 AM1/20/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Hasan Ramezani):

Shouldn't the `Child` class inherits from `Parent` in the regression test?


{{{
class Child(Parent):
pass
}}}

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

Django

unread,
Jan 20, 2021, 6:05:12 AM1/20/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* owner: nobody => Hasan Ramezani
* status: new => assigned


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

Django

unread,
Jan 20, 2021, 6:15:23 AM1/20/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:4 Hasan Ramezani]:


> Shouldn't the `Child` class inherits from `Parent` in the regression
test?
>
>
> {{{
> class Child(Parent):
> pass
> }}}

True, typo.

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

Django

unread,
Jan 20, 2021, 7:39:26 AM1/20/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/32367#comment:7>

Django

unread,
Jan 21, 2021, 3:12:41 AM1/21/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Mariusz Felisiak):

[https://github.com/django/django/pull/13925 Alternative PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32367#comment:8>

Django

unread,
Jan 21, 2021, 1:38:41 PM1/21/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: Hasan
| Ramezani
Type: Bug | Status: closed

Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"a03a36121d22c8784985c7e45727eddef6a3ea7f" a03a3612]:
{{{
#!CommitTicketReference repository=""
revision="a03a36121d22c8784985c7e45727eddef6a3ea7f"
Fixed #32367 -- Fixed system check for specifying type of auto-created
primary keys for inherited PKs.

Regression in b5e12d490af3debca8c55ab3c1698189fdedbbdb.

Thanks אורי for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32367#comment:9>

Django

unread,
Jan 21, 2021, 1:38:51 PM1/21/21
to django-...@googlegroups.com
#32367: models.W042 is raised on inherited manually specified primary key.
-------------------------------------+-------------------------------------
Reporter: אורי | Owner: Hasan
| Ramezani
Type: Bug | Status: closed
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
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:"e45b944d69b6bacaccb22b351a76272aa4f93581" e45b944]:
{{{
#!CommitTicketReference repository=""
revision="e45b944d69b6bacaccb22b351a76272aa4f93581"
[3.2.x] Fixed #32367 -- Fixed system check for specifying type of auto-
created primary keys for inherited PKs.

Regression in b5e12d490af3debca8c55ab3c1698189fdedbbdb.

Thanks אורי for the report.

Backport of a03a36121d22c8784985c7e45727eddef6a3ea7f from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32367#comment:10>

Reply all
Reply to author
Forward
0 new messages