Strange behavior, that I don\'t know how to explain. I\'ve got a model, Track
, with some related points
. I call a celery task to performs some calculat
So, I've solved it using django-transaction-hooks. It still looks kinda scary to replace my DB backend, but django-celery-transactions
seems to be broken in Django 1.6. Now my setup looks like this:
settings.py:
DATABASES = {
'default': {
'ENGINE': 'transaction_hooks.backends.postgresql_psycopg2',
'NAME': 'foo',
},
}
SOUTH_DATABASE_ADAPTERS = {'default':'south.db.postgresql_psycopg2'} # this is required, or South breaks
models.py:
from django.db import connection
@shared_task
def my_task(track):
print 'in the task', track.id, track.points.all().count()
def some_method():
t = Track()
t.save()
t = fill_with_points(t) # creating points, attaching them to a Track
t.save()
print 'before the task', track.id, track.points.all().count()
connection.on_commit(lambda: my_task.delay(t))
Results:
before the task, 21346, 2971
in the task, 21346, 2971
It still seems strange that such a common use case has no native celery or Django solution.