librelist archives

« back to archive

flask-sqlalchemy change poolclass

flask-sqlalchemy change poolclass

Rafał Bolanowski
2014-02-15 @ 10:58
Recently I have encountered a strange behaviour when trying out *flask* with
*flask-sqlalchemy. *It makes it impossible to use *SQLite3* database with
*:memory:* option.

I followed clues provided in

and provided *SQLAlchemy* with *SQLite3* database created in memory.
However, this seems to cause a *OperationalError: no such table *exception.
I tried to debug this issue and found out

that this behaviour is caused by a default *SQLAlchemy's* pool handler
class. By default the library can disconnect from database thus causing
deleting *SQLite* database from memory. The author suggests changing this
to *StaticPool* so that *SQLAlchemy* won't drop connection thus
*SQLite*database should not be dropped and created once again. As far
as I can
tell, this can't be done if using *flask-sqlalchemy* as presented on
mentioned guide.

I wonder if I should report an issue on GitHub or I am missing some way of
overriding pool handler class. Maybe I am using obsolete way of working
with *SQLAlchemy? *Anyway, I would like to hear any feedback regarding this

*With regards,*
*Rafał Bolanowski*