Opened 2 years ago

Last modified 5 weeks ago

#28752 closed Cleanup/optimization

django.setup() should be idempotent — at Version 2

Reported by: pascal chambon Owned by: nobody
Component: Core (Other) Version: 1.11
Severity: Normal Keywords:
Cc: Aymeric Augustin Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by pascal chambon)

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)
        assert logging.getLogger('django').level == logging.DEBUG

        assert logging.getLogger('django').level == logging.DEBUG  # raises

Change History (2)

comment:1 Changed 2 years ago by Tim Graham

Resolution: duplicate
Status: newclosed
Summary: Django.setup() should be idempotentdjango.setup() should be idempotent

I believe this is addressed in Django 2.0 by #27176. If not, please reopen with a minimal project that reproduces the problem you're encountering.

comment:2 Changed 2 years ago by pascal chambon

Description: modified (diff)
Resolution: duplicate
Status: closednew
Note: See TracTickets for help on using tickets.
Back to Top