Django Integration¶
Django-specific components for airlock.
Configuration¶
Configure via settings.py:
AIRLOCK = {
"POLICY": "airlock.AllowAll", # Dotted path or callable
"EXECUTOR": "airlock.integrations.executors.celery.celery_executor",
"SCOPE": "airlock.integrations.django.DjangoScope",
}
Classes¶
DjangoScope ¶
Bases: Scope
A Django-specific scope that respects database transactions.
Defers dispatch to transaction.on_commit() so side effects only
fire after the transaction commits successfully. When called outside
a transaction (autocommit mode), on_commit executes immediately.
If no executor is provided, uses get_executor() to select one based
on EXECUTOR setting.
Subclass and override schedule_dispatch() to customize dispatch timing.
schedule_dispatch ¶
Schedule the dispatch callback. Override to customize dispatch timing.
By default, uses transaction.on_commit(). On Django 5.0+, uses
robust=True so one failing callback doesn't prevent others from running.
This defers dispatch until the transaction commits, or runs immediately if
outside a transaction (autocommit mode).
Override to change timing, robust behavior, or skip on_commit entirely.
AirlockMiddleware ¶
Django middleware that wraps each request in an airlock scope.
By default:
- 1xx/2xx/3xx responses: flush
- 4xx/5xx responses or exceptions: discard
Subclass and override should_flush() for custom behavior.
should_flush ¶
Override to customize flush behavior.
| Returns: |
|
|---|
Functions¶
get_executor ¶
Get the appropriate executor based on EXECUTOR setting.
EXECUTOR should be a dotted import path to an executor callable,
or None for synchronous execution.
Example::
AIRLOCK = {
'EXECUTOR': 'airlock.integrations.executors.django_q.django_q_executor',
}
# Or use a custom executor
AIRLOCK = {
'EXECUTOR': 'myapp.executors.custom_executor',
}
| Returns: |
|
|---|
| Raises: |
|
|---|