Registering signal handlers

46 views
Skip to first unread message

Curtis Maloney

unread,
Dec 22, 2013, 3:22:29 AM12/22/13
to django-d...@googlegroups.com
Reading the posts on App reconfigure reminded me I wanted to raise this for discussion.

Recently we've been suffering circular imports, and the majority are, IMHO, caused by people importing "receivers" in the apss __init__.py.

By convention [in our app, at least] "receivers.py" registers all the signal receivers.

However, as Aymeric points out, puttng code in __init__ is a prime candidate for triggering circular imports.

A lot of times we can avoid the problems by breaking the loops with get_model(), however it generally gets applied elsewhere.  We can't always do this in models.py, because often that would require importing other models, and I avoid that as much as possible.

So I tried an autodiscover mechanism, just admin, to make it clean, clear and obvious as to when all the receivers were hooked.

But...

When to run it?

If I put it in urls.py, like admin.autodiscover, can I be sure it will be triggered for, say, my celery tasks? Or management commands?  I could put it at the end of settings.py, but that just feels wrong.

I'm happy to trace the whole of Django from go to whoa, and decide on a place to put it, but I'd like to hear from the community in general for ideas.

--
Curtis

charettes

unread,
Dec 22, 2013, 3:55:19 AM12/22/13
to django-d...@googlegroups.com
Since Django 1.7 you can lazily reference model signal sender, it might help solving your circular import issues.

It seems providing a reliable initialization signal is one of Aymeric's main goal.

Simon

Curtis Maloney

unread,
Dec 22, 2013, 4:16:15 AM12/22/13
to django-d...@googlegroups.com
Well, if you were looking to do so in 1.6 for the scores of suffering developers _now_... what would you do?


--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/643a1e10-f4c8-4a90-a96e-17620e7c9843%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages