Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32863 closed Bug (fixed)

Model.check() crashes with invalid app label and no explicit DEFAULT_AUTO_FIELD

Reported by: Iuri de Silvio Owned by: Hasan Ramezani
Component: Database layer (models, ORM) Version: 3.2
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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)

comment:1 by Jacob Walls, 4 years ago

Summary: Model.check() crashes on Django 3.2 with invalid app labelModel.check() crashes with invalid app label and no explicit DEFAULT_AUTO_FIELD
Triage Stage: UnreviewedAccepted

Thanks for reporting.

Reproduced at 225d96533a8e05debd402a2bfe566487cc27d95f.
Regression in b5e12d490af3debca8c55ab3c1698189fdedbbdb.

comment:2 by Mariusz Felisiak, 4 years ago

Severity: NormalRelease blocker

comment:3 by Hasan Ramezani, 4 years ago

Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:4 by Hasan Ramezani, 4 years ago

Has patch: set

comment:5 by Mariusz Felisiak, 4 years ago

Needs documentation: set
Patch needs improvement: set

comment:6 by Hasan Ramezani, 4 years ago

Needs documentation: unset
Patch needs improvement: unset

comment:7 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 7a9745fe:

Fixed #32863 -- Skipped system check for specifying type of auto-created primary keys on models with invalid app_label.

Regression in b5e12d490af3debca8c55ab3c1698189fdedbbdb.

Thanks Iuri de Silvio for the report.

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

In 8b2b627f:

[3.2.x] Fixed #32863 -- Skipped system check for specifying type of auto-created primary keys on models with invalid app_label.

Regression in b5e12d490af3debca8c55ab3c1698189fdedbbdb.

Thanks Iuri de Silvio for the report.

Backport of 7a9745fed498f69c46a3ffa5dfaff872e0e1df89 from main

Note: See TracTickets for help on using tickets.
Back to Top