#23641: Apps.set_installed_apps causes signals registered with apps as senders 
not
to be received
------------------------------+------------------------------------
     Reporter:  wrwrwr        |                    Owner:  nobody
         Type:  Bug           |                   Status:  new
    Component:  Core (Other)  |                  Version:  master
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Accepted
    Has patch:  0             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+------------------------------------

Comment (by wrwrwr):

 Thanks for the quick response. Good news is that scanning the source for
 ".connect(", "@receiver(" and "sender=" didn't reveal any other cases of
 using `AppConfig` as a sender, so for consistency I've only also moved
 `post_migrate` registration for `auth` and `contenttypes` to `ready` (both
 need to be called for every migration, not just their app migration, so
 don't specify any sender to `connect`).

 On the other hand, theoretically the issue can be triggered without
 directly using `set_installed_apps`; the following test fails as is, but
 succeeds if you comment out the `modify_settings` decorator:
 {{{#!python
 from django.apps import apps
 from django.dispatch import Signal, receiver
 from django.test import TestCase, modify_settings

 some_signal = Signal()
 app_label = 'auth'  # Something installed.
 handler_called = False

 @receiver(some_signal, sender=apps.get_app_config(app_label))
 def signal_handler(sender, **kwargs):
     global handler_called
     handler_called = True

 @modify_settings(INSTALLED_APPS={})
 class Test(TestCase):
     def test_handler(self):
         some_signal.send(apps.get_app_config(app_label))
         self.assertTrue(handler_called)
 }}}

 This is probably an edge case no one will ever run into, nevertheless the
 behavior may be somewhat surprising.

 How about adding a note to the docs, say something like:
   If you provide an `AppConfig` instance as the sender argument, please
 ensure that the signal is registered in `AppConfig.ready` as app configs
 can be reinstantiated during testing.
 at the [https://docs.djangoproject.com/en/dev/ref/signals/#management-
 signals `pre/post_migrate/syncdb` documentation] (seems unlikely that
 anyone would use an app config as a sender for any other signal)?

--
Ticket URL: <https://code.djangoproject.com/ticket/23641#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.eb1ca83bd65a209b0c73c0374a9f76a9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to