vendredi 26 juin 2015

CELERY_ALWAYS_EAGER in unit tests causes DetachedInstanceError

I added some celery tasks to my python app, and they work great. I'm trying to fix my test suite for celery as well. I added celery.conf.CELERY_ALWAYS_EAGER = True to my test suite so that it can run with the tasks executed synchronously.

Problem is that random tests (that do not even use the celery task) are showing the error DetachedInstanceError: Parent instance <MyModel at 0x1096ba690> is not bound to a Session; lazy load operation of attribute 'child' cannot proceed.

Removing celery.conf.CELERY_ALWAYS_EAGER = True fixes the problem, but then the celery tasks are sent to the queue but not processed unless I start a worker in the terminal.

Aucun commentaire:

Enregistrer un commentaire