Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Transaction barriers for Django and Celery.

Project Description

django_transaction_barrier provides a barrier-like abstraction for transactions. A Django application developer can use a “transaction barrier” to spawn a task within a transaction and guarantee that the task blocks until it’s able to access the updates made in the transaction. django_transaction_barrier is designed with Celery in mind and provides a Celery task base class. Using the base class it’s easy to write code that atomically modifies the database and spawns a Celery task that executes after the transaction commits.


Install from source or use pip:

pip install django_transaction_barrier

and add “django_transaction_barrier” to INSTALLED_APPS in



from celery import task
from django.db import transaction
from django_transaction_barrier.celery import TransactionBarrierTask

def do_something_task(model_id):
  value = Model.objects.get(id=model_id).value

def kick_off_task(model, value):
    model.value = value


If an application spawns an asynchronous TransactionBarrierTask the task is guaranteed to execute eventually (assuming a durable task queue) after the transaction commits. If the transaction aborts, the task raises a TransactionAborted exception and does not execute. In autocommit mode (i.e., “outside of a transaction”) TransactionBarrierTasks behave like normal Celery tasks.

If an application synchrnously executes a TransactionBarrierTask (e.g., with Celery eager mode) within a transaction, the task executes immediately without waiting for the transaction to commit.


django_transaction_barrier implements transaction barriers using row insertion to signify a committed transaction and some DB-specifc logic to detect an abort.


docker build -t tests . && docker run tests


  • Add support for a mysql backend.

Release History

This version
History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(7.6 kB) Copy SHA256 Hash SHA256
Source None Feb 23, 2015

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate