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

-- 
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-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@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/CAG_XiSCUci%3DvZJKjUj6ZbbsFXUb__YGy2phRJtRjUcJJyca2vg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to