[Django] #25445: `AttributeError` when `app_config` is missing attribute `models_module` in contenttypes/mananagent.py

9 views
Skip to first unread message

Django

unread,
Sep 22, 2015, 12:36:30 PM9/22/15
to django-...@googlegroups.com
#25445: `AttributeError` when `app_config` is missing attribute `models_module` in
contenttypes/mananagent.py
--------------------------------------+--------------------
Reporter: pygeek | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
```
if not app_config.models_module:
return
```

The return statement is never reached since if app_config doesn't have a
`models_module` attribute it raises an AttributeError.

Regardless of whether to allow the return statement to catch or return an
AttributeError, this code should perhaps be changed to be more clear. I
suggest either raising an AttributeError explicitly or using gettattr.

https://github.com/django/django/pull/5338

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

Django

unread,
Sep 22, 2015, 12:37:00 PM9/22/15
to django-...@googlegroups.com
#25445: `AttributeError` when `app_config` is missing attribute `models_module` in
contenttypes/management.py
-------------------------------------+-------------------------------------
Reporter: pygeek | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0


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

Django

unread,
Sep 22, 2015, 12:37:11 PM9/22/15
to django-...@googlegroups.com
#25445: `AttributeError` when `app_config` is missing attribute `models_module` in
contenttypes/management.py
-------------------------------------+-------------------------------------
Reporter: pygeek | Owner: pygeek
Type: | Status: assigned
Cleanup/optimization |
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

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

* owner: nobody => pygeek
* status: new => assigned


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

Django

unread,
Sep 22, 2015, 12:40:54 PM9/22/15
to django-...@googlegroups.com
#25445: `AttributeError` when `app_config` is missing attribute `models_module` in
contenttypes/management.py
-------------------------------------+-------------------------------------
Reporter: pygeek | Owner: pygeek
Type: | Status: assigned
Cleanup/optimization |
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by pygeek:

Old description:

> ```
> if not app_config.models_module:
> return
> ```
>
> The return statement is never reached since if app_config doesn't have a
> `models_module` attribute it raises an AttributeError.
>
> Regardless of whether to allow the return statement to catch or return an
> AttributeError, this code should perhaps be changed to be more clear. I
> suggest either raising an AttributeError explicitly or using gettattr.
>
> https://github.com/django/django/pull/5338

New description:

{{{
if not app_config.models_module:
return
}}}


The return statement is never reached since if `app_config` doesn't have a

`models_module` attribute it raises an `AttributeError`.

Regardless of whether to allow the return statement to catch or return an

`AttributeError`, this code should perhaps be changed to be more clear. I
suggest either raising an `AttributeError` explicitly or using `gettattr`.

https://github.com/django/django/pull/5338

--

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

Django

unread,
Sep 22, 2015, 2:41:28 PM9/22/15
to django-...@googlegroups.com
#25445: `AttributeError` when `app_config` is missing attribute `models_module` in
contenttypes/management.py
-------------------------------------+-------------------------------------
Reporter: pygeek | Owner: pygeek
Type: | Status: closed
Cleanup/optimization |
Component: Uncategorized | Version: 1.8
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

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

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


Comment:

Have you encountered an error in practice or are you simply suggesting
this fix based on code inspection?

Considering that `AppConfig.__init__` assigns `self.models_module = None`,
I fail to see how `models_module` can be missing.

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

Reply all
Reply to author
Forward
0 new messages