Fixed #23670 -- Prevented partial import state during module autodiscovery

Ticket: https://code.djangoproject.com/ticket/23670