I am using flask sqlalchemy and celery to run tasks and here is my code.
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy(model_class=Base)
But when I run the worker, I keep getting this weird error.
The reason is that one task closes the db session before others finish db transaction and sqlalchemy is sharing a session between the celery tasks.
sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (2013, 'Lost connection to MySQL server during query')