#22029 closed Cleanup/optimization (fixed)
documentation: new best place to put the signal handler registration
Reported by: | Val Neekman | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | vneekman@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The new best place for registering the signal handlers are in the ready() of the AppConfig.
This way, the signals properly emit with the server starts and also via the django-admin shell.
The documentation would benefit from an update indicating the new feature of Django 1.7.
The following section may require the update.
https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_migrate
https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.post_migrate
This:
"Any handlers that listen to this signal need to be written in a particular place: a management module in one of your INSTALLED_APPS. If handlers are registered anywhere else they may not be loaded by migrate."
Could be changed to:
"Any handlers that listen to this signal need to be written in a particular place: the AppConfig.ready() within the apps module in one of your INSTALLED_APPS. If handlers are registered anywhere else they may not be loaded by migrate."
Attachments (1)
Change History (8)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 11 years ago
Attachment: | 22029.diff added |
---|
comment:3 by , 11 years ago
Has patch: | set |
---|
I wonder if we need to mention this as something specific to these signals though? Can we assume all signals will now be registered in AppConfig.ready()
?
comment:4 by , 11 years ago
I didn't check the commit logs, but the wording sounds like this is a warning against registering signals in urls.py (for instance). I don't think these signals are a special case any more.
comment:5 by , 11 years ago
The current docs says that you "need to" register these signals in the management module or else.
This is not the case anymore ... AppConfig.ready() is a better place, right Aymeric?
Also, circular dependencies are no longer the issue if these signals are registering in AppConfig.ready() and yes, no need to register in urls.py are more.
In short: "need to" is no longer true.
comment:6 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Also:
This:
"Sent by the migrate command before it starts to install an application."
Could be changed to:
"Sent by the migrate command before it starts to install an application that has a models module."