#28752: django.setup() should be idempotent
--------------------------------+--------------------------------------
Reporter: pascal chambon | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 1.11
Severity: Normal | Resolution:
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 pascal chambon):
* status: closed => new
* resolution: duplicate =>
Old description:
> I've been bitten numerous times by the impredictable behaviour of django
> when django.setup() was called numerous times.
>
> In the old days I had exceptions, now it's mainly subtle breakages of
> logging configuration.
>
> I couldn't find, in the issue tracker or the dev mailing list statements
> about this subject, others than request from other users encountering the
> problem.
>
> For example this ticket concerned script+importable modules :
> https://code.djangoproject.com/ticket/26152
>
> The latest case in date for me is pytest-django having troubles with
> these multiple setup() calls : https://github.com/pytest-dev/pytest-
> django/issues/531 , due to multiple fixtures attempting this auto-setup.
>
> Would it be OK to make django.setup() idempotent, or even expose a
> "is_ready" flag for easier introspection ?
New description:
Alas the ticket #27176 dealt only with the "apps.populate" part, but the
whole setup() must be protected, else we'll always have weird side effects
on duplicate calls.
Here is a testcase showing the reset of the "django" logger level, for
example, when calling setup() multiple times.
Depending on the exact LOGGING dict (with disable_existing_loggers etc.),
even the shape of the logging tree might be changed.
{{{
def test_duplicated_setup_calls(self):
import django, logging
#from django.conf import settings
#print(settings.LOGGING_CONFIG, settings.LOGGING)
django.setup()
logging.getLogger('django').setLevel(logging.DEBUG)
assert logging.getLogger('django').level == logging.DEBUG
django.setup()
assert logging.getLogger('django').level == logging.DEBUG #
raises
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/28752#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.dc42aee0058368e02acc12fc377cf910%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.