﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23641	Apps.set_installed_apps causes signals registered with apps as senders not to be received	Wojtek Ruszczewski	nobody	"Calling `Apps.set_installed_apps` before `DiscoverRunner.setup_databases` causes pre/post_migrate signal handlers registered on module import with app configs as senders not to be executed for the test database.

The signal dispatcher stores `id()` of the  sender argument provided to `connect` to identify the sender that we're interested in receiving the signals from, in case of `post_migrate` signals this is often an id of an `AppConfig` for the registering app. When `set_installed_apps` is called it reinstantiates all app configs. If afterwards you send a signal using app config from the global app registry as the sender (as is the case in `emit_post_migrate_signal` when setting up test databases), its id won't match the one stored by the dispatcher, thus signal handlers won't get executed.

[https://github.com/wrwrwr/django/tree/fix/missing-default-site-with-set-installed-apps A branch] with an example test case and a possible partial fix (that in full would be moving all module-level signal registration to `AppConfig.ready`).

[https://github.com/wrwrwr/mezzanine/blob/maintenance/1.8-discover-test-runner/mezzanine/utils/tests.py#L117 A sketch] of a possible more general solution / workaround (this Mezzanine wrapper for `DiscoverRunner` turned out pretty involved, you're welcome to suggest a cleaner implementation :-)

See also #22688: AppConfig.ready is going to get called for every instance, so should be a good place to put these signal registrations."	Bug	new	Core (Other)	dev	Normal				Unreviewed	0	0	0	0	0	0
