🛡️ django-signal-guard
Make Django signal failures loud.
Catch the bulk writes that silently skip your pre_save / post_save receivers,
the receivers that never get connected, and the ones that run twice.
Quick start • Bypass guard • System checks • signals.lock • Configuration • How it works
💥 The problem
Order.objects.bulk_create(rows) # post_save never fires
Order.objects.filter(...).update(...) # neither does pre_save
bulk_create(), bulk_update() and update() write rows without calling
Model.save(), so your pre_save and post_save receivers never run.
Nothing errors. The search index goes stale, the audit log has gaps, a cache is never invalidated. You usually find out days later, in production.
✅ The fix
django-signal-guard catches those writes in development, tests and CI, and
tells you exactly which receivers were skipped and where the call came from:
SignalBypassError: QuerySet.bulk_create() on shop.Order skips 2 receivers:
pre_save shop.signals.normalize_status (shop/signals.py:5)
post_save shop.signals.reindex_order (shop/signals.py:9)
Called from shop/imports.py:42.
Run the receivers' work yourself, or wrap the call in signal_guard.allow_bypass(Order, reason="...").
It doesn't add new signals or replace them with hooks. Your signals stay
exactly as they are. It just reports misuse, the way
nplusone and
django-seal report lazy queries.
✨ What's inside
| Feature | What it catches | |
|---|---|---|
| 🚧 | Bypass guard | Bulk writes that skip receivers: raise, warn or log. |
| 🩺 | System checks | Receivers that never run, only run in some processes, die silently, or run twice. |
| 🔒 | signals.lock |
A committed inventory of every receiver, checked in CI, so new receivers show up in code review. |
📦 Install
pip install django-signal-guard
Requires Python 3.10+ and Django 5.2+.
🚀 Quick start
1. Add it to INSTALLED_APPS, first in the list:
# settings.py
INSTALLED_APPS = [
"signal_guard", # first, so it sees every receiver being connected
# ...
]
2. Make bypasses fail your tests:
# settings/test.py
SIGNAL_GUARD = {"BYPASS": "raise"}
3. Add two lines to CI:
python manage.py check --tag signals --fail-level WARNING
python manage.py signal_map --check
That's it. Everywhere else, the default is "warn".
🚧 The bypass guard
Every bulk_create(), bulk_update() and update() (plus abulk_create(),
abulk_update(), aupdate()) is checked against the live pre_save and
post_save receivers for that model. A model with no receivers costs a single
has_listeners() call.
When skipping is intended
Wrap the call in allow_bypass and say why. The reason is required, so
the decision is written down next to the code:
from signal_guard import allow_bypass
with allow_bypass(Order, reason="import reindexes in one batch"):
Order.objects.bulk_create(rows)
reindex_orders(rows)
allow_bypass()with no models allows every model.- It also works as a decorator and with
async with.
Receivers that never matter for bulk writes
Mark them once with @bulk_safe:
from django.db.models.signals import post_save
from django.dispatch import receiver
from signal_guard import bulk_safe
@receiver(post_save, sender=Order)
@bulk_safe
def warm_cache(sender, instance, **kwargs): ...
What the guard covers, and what it doesn't
Covered
bulk_create(),bulk_update()andupdate(), called on a manager, a queryset, or your ownQuerySetsubclass methods.- The async variants
abulk_create(),abulk_update()andaupdate(). - Receivers connected to the model, and receivers connected to every sender.
bulk_update()is reported once, even though Django runsupdate()inside it.
Not covered
- Raw SQL,
cursor.execute(), database triggers and other writes that never go through aQuerySet. QuerySet.delete(). It does sendpre_deleteandpost_delete; it only skips your model's owndelete()method.- Logic in an overridden
Model.save()with no signal receiver. The guard only knows about receivers. - A
QuerySetsubclass that overrides one of the three methods and never callssuper().
🩺 System checks
python manage.py check --tag signals
| ID | Finds | Why it matters |
|---|---|---|
W001 |
A module in one of your apps defines @receiver functions, but nothing imports it. |
The decorator never runs, so the receiver never runs. The classic "my signal doesn't fire". |
W002 |
A receiver is connected only after startup, by a lazy import such as views.py importing your signals module. |
Web requests run it, but Celery workers, management commands and some tests never do. |
W003 |
A weakly connected function or lambda was garbage-collected. | Django holds receivers by weak reference, so a nested function or lambda silently stops running. |
W004 |
The same receiver is connected more than once to one signal and sender. | Every copy runs, so emails go out twice. |
Example output
shop.webhooks: (signal_guard.W002) shop.webhooks.send_webhook is connected only after startup, when shop/views.py:2 imports it.
HINT: Processes that never run that import, such as Celery workers, management commands and some tests, never run this receiver. Import shop.webhooks in shop.apps.ShopConfig.ready().
All four are warnings, so they never stop runserver. Silence one with
SILENCED_SYSTEM_CHECKS = ["signal_guard.W004"].
🔒 The signal map and signals.lock
See which receivers run for which signal and sender: yours, plus third-party
receivers that run on your models (add --all for Django's internals).
$ python manage.py signal_map
First-party receivers (3)
django.db.models.signals.post_save
shop.Order
shop.signals.reindex_order (shop/signals.py:9)
shop.webhooks.send_webhook (shop/webhooks.py:6)
django.db.models.signals.pre_save
shop.Order
shop.signals.normalize_status (shop/signals.py:5)
Commit the same list as a lock file:
python manage.py signal_map --write # writes signals.lock
python manage.py signal_map --check # fails with a diff when it's out of date
[first-party]
django.db.models.signals.post_save | shop.Order | shop.signals.reindex_order
django.db.models.signals.post_save | shop.Order | shop.webhooks.send_webhook
django.db.models.signals.pre_save | shop.Order | shop.signals.normalize_status
One line per receiver, no line numbers, so the file only changes when a receiver is added, removed or moved. That includes receivers a dependency upgrade quietly adds to your models.
⚙️ Configuration
Every key is optional:
SIGNAL_GUARD = {
"BYPASS": "warn", # raise | warn | log | off
"IGNORE_RECEIVERS": [], # fnmatch patterns, e.g. ["simple_history.*"]
"CHECK_LIBRARY_CALLS": False,
"FIRST_PARTY": None, # e.g. ["shop", "billing"]
"LOCK_FILE": "signals.lock",
"ENABLED": True,
}
| Key | Default | Description |
|---|---|---|
BYPASS |
"warn" |
raise stops the write with SignalBypassError before anything reaches the database. warn emits a SignalBypassWarning. log writes to the signal_guard logger. off does nothing. |
IGNORE_RECEIVERS |
[] |
Receivers whose dotted path matches one of these patterns are never reported. Handy for third-party receivers you can't change. |
CHECK_LIBRARY_CALLS |
False |
Also report bulk writes made inside Django or installed packages, such as the UPDATE behind on_delete=SET_NULL. |
FIRST_PARTY |
None |
Module prefixes of your own code. By default, anything not Django and not in site-packages counts as yours. |
LOCK_FILE |
"signals.lock" |
Where signal_map --write / --check keep the lock file. Relative paths resolve against settings.BASE_DIR when it exists. |
ENABLED |
True |
When False at startup, nothing is wrapped and the checks do nothing. |
Tip: settings are read on every call, so
override_settingsjust works in tests.
🔍 How it works
flowchart LR
A["Order.objects.bulk_create(rows)"] --> B{"pre_save / post_save<br/>listeners?"}
B -- no --> W[("write to DB")]
B -- yes --> C{"allow_bypass,<br/>@bulk_safe or<br/>IGNORE_RECEIVERS?"}
C -- all covered --> W
C -- some left --> D["report skipped receivers<br/>+ call site"]
D -- raise --> X["SignalBypassError<br/>(nothing written)"]
D -- warn / log --> W
- Bypass guard. On app load it wraps
QuerySet.bulk_create,bulk_updateandupdate. Before each write it asks Django's dispatcher whichpre_saveandpost_savereceivers are live for the model, drops those marked@bulk_safeor matchingIGNORE_RECEIVERS, and reports the rest. - Registry. It wraps
Signal.connect()anddisconnect()to record where and when each receiver was connected. It holds only weak references, so it never keeps a receiver alive. That's whysignal_guardshould come first inINSTALLED_APPS: a receiver connected before it loads has no record, so W003 can't see it die. - Checks and map. They import your URLconf first, as a running server
would, then read Django's live receivers. W001 also parses your apps' modules
(skipping tests and migrations) to find
@receiverfunctions.
🗺️ Roadmap
| Version | Adds | |
|---|---|---|
| 0.1 | Bypass guard | ✅ |
| 0.2 | System checks W001–W004, manage.py signal_map, signals.lock |
✅ |
| 0.3 | Recursion tracing, @receiver_on_commit, a check for side effects before commit |
🔜 |
| 1.0 | pytest plugin and test assertions, full documentation | 🔜 |
See the changelog for details.
📚 Prior art
- Johnny Metz's post on blocking bulk operations that skip signals, which
shows the same idea as a custom
QuerySet. django-bulk-signals,django-bulk-trackerand similar packages add new bulk signals. Use them if you want receivers that do run on bulk writes;django-signal-guardtells you when your existing receivers don't.django-lifecyclereplaces signals with model hooks.
🧑💻 Development
uv sync --group dev
uv run pytest
uv run ruff check . && uv run ruff format --check .
Issues and pull requests are welcome.
📄 License
BSD-3-Clause, the same as Django.
Metadata
Release files for django-signal-guard 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_signal_guard-0.2.0.tar.gz | 26.8 kB | With provenance | Details for django_signal_guard-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_signal_guard-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for django_signal_guard-0.2.0-py3-none-any.whl |
Total release size: 53.5 kB
Release files / django_signal_guard-0.2.0.tar.gz
| Download URL | django_signal_guard-0.2.0.tar.gz |
|---|---|
| Size | 26.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56754f835ad26765a73c87dded6cb3e8e4c0a37009d3020cce7f2d7ac1e44374
|
|
BLAKE2b-256 checksum How to use checksums |
a7bd8510f02f13211d51b193391e7037ab1399af61e1b4f6b5008946a8a73332
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logRelease files / django_signal_guard-0.2.0-py3-none-any.whl
| Download URL | django_signal_guard-0.2.0-py3-none-any.whl |
|---|---|
| Size | 26.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33a9c80a5208a6aaeb6b17b5a6b7042fb633050eaa0bfb27736ed442e9befa28
|
|
BLAKE2b-256 checksum How to use checksums |
ad187042dda87c2cef1c047a8ee593c0e0fce4d31a229ad39606d5a7ec96418f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logSecurity for django-signal-guard 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_signal_guard-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.