[Django] #32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with AttributeError

0 views
Skip to first unread message

Django

unread,
May 10, 2021, 8:55:52 AM5/10/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 3.2
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Here is a simple code that shows different behaviour between 3.1 and 3.2:

{{{
from django.db import models
class MyAbstractModel(models.Model):
class Meta:
abstract = True

# behaviour in 3.1.10:
MyAbstractModel.check() # returns []

# behaviour in 3.2:
MyAbstractModel.check() # raises AttributeError: 'NoneType' object has no
attribute 'auto_created' in `_check_default_pk`
}}}

It seems to me (but I might be wrong here) that this was not an
intentional change (as the feature is all about default autofield), but
rather a bug.
However, feel free to correct me!

Best,
Rust

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

Django

unread,
May 10, 2021, 9:42:06 AM5/10/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | 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 Johannes Maron):

* cc: Johannes Maron (added)
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

It is arguable, whether if the checks need to work on an abstract class. I
also noticed that Django will raise an error since 3.2 if you try to
instantiate an abstract model.
Though, there is no place where checks are called on abstract models
inside an application, this does make unit testing harder.

With that in mind, maybe this is best classified as an optimization not a
bug, since no public API is broken, not does this affect the application
itself. However, since Django is a developer-friendly framework and comes
with an excellent test suite, I believe an improvement would be welcome by
many.

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

Django

unread,
May 10, 2021, 4:27:19 PM5/10/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | 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 amureki):

Replying to [comment:1 Johannes Maron]:


> It is arguable, whether if the checks need to work on an abstract class.
I also noticed that Django will raise an error since 3.2 if you try to
instantiate an abstract model.
> Though, there is no place where checks are called on abstract models
inside an application, this does make unit testing harder.
>
> With that in mind, maybe this is best classified as an optimization not
a bug, since no public API is broken, not does this affect the application
itself. However, since Django is a developer-friendly framework and comes
with an excellent test suite, I believe an improvement would be welcome by
many.

Thanks, Johannes!

I made a draft [https://github.com/django/django/pull/14375 PR] with blunt
solution - freshly introduced auto-field check would not run on abstract
models.
I am more than happy to get better ideas or any other feedback!

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

Django

unread,
May 10, 2021, 4:27:47 PM5/10/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: amureki
Type: | Status: assigned

Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by amureki):

* owner: nobody => amureki
* status: new => assigned
* has_patch: 0 => 1
* needs_tests: 0 => 1


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

Django

unread,
May 11, 2021, 6:14:23 AM5/11/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: amureki
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Johannes Maron):

* needs_better_patch: 0 => 1


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

Django

unread,
May 17, 2021, 4:33:21 AM5/17/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: amureki
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by amureki):

* needs_better_patch: 1 => 0


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

Django

unread,
May 18, 2021, 4:47:10 AM5/18/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: amureki
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* needs_tests: 1 => 0
* stage: Accepted => Ready for checkin


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

Django

unread,
May 18, 2021, 7:04:19 AM5/18/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: amureki
Type: | Status: assigned
Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution:

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* severity: Normal => Release blocker


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

Django

unread,
May 18, 2021, 7:33:52 AM5/18/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: amureki
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
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:"a24fed399ced6be2e9dce4cf28db00c3ee21a21c" a24fed39]:
{{{
#!CommitTicketReference repository=""
revision="a24fed399ced6be2e9dce4cf28db00c3ee21a21c"
Fixed #32733 -- Skipped system check for specifying type of auto-created
primary keys on abstract models.

Regression in b5e12d490af3debca8c55ab3c1698189fdedbbdb.
}}}

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

Django

unread,
May 18, 2021, 7:34:03 AM5/18/21
to django-...@googlegroups.com
#32733: DEFAULT_AUTO_FIELD feature leads `AbstractModel.check()` to fail with
AttributeError
-------------------------------------+-------------------------------------
Reporter: amureki | Owner: amureki
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 3.2
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
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:"349bb58b8a0b6f4b98193dbfe369e41b8780f225" 349bb58b]:
{{{
#!CommitTicketReference repository=""
revision="349bb58b8a0b6f4b98193dbfe369e41b8780f225"
[3.2.x] Fixed #32733 -- Skipped system check for specifying type of auto-
created primary keys on abstract models.

Regression in b5e12d490af3debca8c55ab3c1698189fdedbbdb.

Backport of a24fed399ced6be2e9dce4cf28db00c3ee21a21c from main
}}}

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

Reply all
Reply to author
Forward
0 new messages