[Django] #29906: `isinstance(django_settings, type)` triggers ImproperlyConfigured, although settings are not really accessed

6 views
Skip to first unread message

Django

unread,
Oct 30, 2018, 10:12:57 AM10/30/18
to django-...@googlegroups.com
#29906: `isinstance(django_settings, type)` triggers ImproperlyConfigured, although
settings are not really accessed
-----------------------------------------+------------------------
Reporter: Daniel Hahler | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.1
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 |
-----------------------------------------+------------------------
Checking if `django.conf.settings` is a class should not trigger an
exception, but the following code triggers ImproperlyConfigured already:

```
from django.conf import settings as django_settings
isinstance(django_settings, type)
```

(via https://github.com/pytest-dev/pytest/issues/4266)

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

Django

unread,
Oct 30, 2018, 10:26:56 AM10/30/18
to django-...@googlegroups.com
#29906: `isinstance(django_settings, type)` triggers ImproperlyConfigured, although
settings are not really accessed
-------------------------------+--------------------------------------

Reporter: Daniel Hahler | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 2.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => invalid


Comment:

As mentioned on the linked PR this has little to do with the `isinstance`
check; accessing `django.conf.settings` attributes (in this case
`__class__` through `isinstance`) is prohibited until
[https://docs.djangoproject.com/en/2.1/topics/settings/#calling-django-
setup-is-required-for-standalone-django-usage settings are configured].

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

Django

unread,
Oct 30, 2018, 11:36:51 AM10/30/18
to django-...@googlegroups.com
#29906: `isinstance(django_settings, type)` triggers ImproperlyConfigured, although
settings are not really accessed
-------------------------------+--------------------------------------

Reporter: Daniel Hahler | Owner: nobody
Type: Bug | Status: closed
Component: Core (Other) | Version: 2.1
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Bug
* component: Uncategorized => Core (Other)


Old description:

> Checking if `django.conf.settings` is a class should not trigger an
> exception, but the following code triggers ImproperlyConfigured already:
>
> ```
> from django.conf import settings as django_settings
> isinstance(django_settings, type)
> ```
>
> (via https://github.com/pytest-dev/pytest/issues/4266)

New description:

Checking if `django.conf.settings` is a class should not trigger an
exception, but the following code triggers ImproperlyConfigured already:

{{{
from django.conf import settings as django_settings
isinstance(django_settings, type)
}}}

(via https://github.com/pytest-dev/pytest/issues/4266)

--

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

Django

unread,
Oct 31, 2018, 8:12:09 PM10/31/18
to django-...@googlegroups.com
#29906: `isinstance(django_settings, type)` triggers ImproperlyConfigured, although
settings are not really accessed
-------------------------------+--------------------------------------

Reporter: Daniel Hahler | Owner: nobody
Type: Bug | Status: closed
Component: Core (Other) | Version: 2.1
Severity: Normal | Resolution: invalid
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 Daniel Hahler):

Just for the record: it is not via ``__getattr__``, but because
``__class__`` itself is special property already:
https://github.com/django/django/blob/3d4d0a25b299a97314582156a0d63d939662d310/django/utils/functional.py#L305

I still think that ``isinstance()`` should not throw, but created a
fix/workaround for pytest nonetheless.

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

Reply all
Reply to author
Forward
0 new messages