Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#29906 closed Bug (invalid)

`isinstance(django_settings, type)` triggers ImproperlyConfigured, although settings are not really accessed

Reported by: Daniel Hahler Owned by: nobody
Component: Core (Other) Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

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)

Change History (3)

comment:1 by Simon Charette, 6 years ago

Resolution: invalid
Status: newclosed

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 settings are configured.

comment:2 by Tim Graham, 6 years ago

Component: UncategorizedCore (Other)
Description: modified (diff)
Type: UncategorizedBug

comment:3 by Daniel Hahler, 6 years ago

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.

Last edited 6 years ago by Daniel Hahler (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top