Hacker News new | ask | show | jobs
by bsaul 4550 days ago
Currently on a big project using flask + sqlalchemy and didn't want to use flask-sqlalchemy as well. At first, it was because it didn't seem like i needed to, then it was for a better understanding of the sqlalchemy session / flask request lifecycle coordination. That knowledge proved to be very useful once i needed to reuse my stack in a celery task.
1 comments

To solve this, I have a custom Celery instance that wraps each task in my flask app's context. So you can treat celery tasks as just another request.
Yeap, that's what i did as well, and i think that's the documented way ( using a flask test request context i think). But having to do this let me understand a lot more about sqlalchemy session, flushing and object states, in a multithreaded environment. I recommend doing that for an in-depth understanding.