Model.check() crashes with invalid app label and no explicit DEFAULT_AUTO_FIELD
I found this issue in django-cryptography
lib (https://github.com/georgemarshall/django-cryptography). They have a test with an invalid app_label
, I'd expect model check to return False
, but it crashes when DEFAULT_AUTO_FIELD
is not defined, because _meta.app_config=None
.
In [1]: from django.db import models
...: class Foo(models.Model):
...: class Meta:
...: app_label = 'bar'
...:
In [2]: Foo.check()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-f17a07bccce5> in <module>
----> 1 Foo.check()
~django/db/models/base.py in check(cls, **kwargs)
1291 *cls._check_ordering(),
1292 *cls._check_constraints(databases),
-> 1293 *cls._check_default_pk(),
1294 ]
1295
~django/db/models/base.py in _check_default_pk(cls)
1307 ) and
1308 not settings.is_overridden('DEFAULT_AUTO_FIELD') and
-> 1309 not cls._meta.app_config._is_default_auto_field_overridden
1310 ):
1311 return [
AttributeError: 'NoneType' object has no attribute '_is_default_auto_field_overridden'
Change History
(9)
Summary: |
Model.check() crashes on Django 3.2 with invalid app label → Model.check() crashes with invalid app label and no explicit DEFAULT_AUTO_FIELD
|
Triage Stage: |
Unreviewed → Accepted
|
Severity: |
Normal → Release blocker
|
Owner: |
changed from nobody to Hasan Ramezani
|
Status: |
new → assigned
|
Needs documentation: |
set
|
Patch needs improvement: |
set
|
Needs documentation: |
unset
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
Thanks for reporting.
Reproduced at 225d96533a8e05debd402a2bfe566487cc27d95f.
Regression in b5e12d490af3debca8c55ab3c1698189fdedbbdb.