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

Thanks kostko for the report.