Opened 10 years ago

Last modified 10 years ago

#23641 closed Bug

Apps.set_installed_apps causes signals registered with apps as senders not to be received — at Initial Version

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

Description

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.

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).

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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top