librelist archives

« back to archive

flask-sqlalchemy change poolclass

flask-sqlalchemy change poolclass

From:
Rafał Bolanowski
Date:
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

this<http://pythonhosted.org/Flask-SQLAlchemy/quickstart.html#a-minimal-application>
guide
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

([1]<http://www.sameratiani.com/2013/09/17/flask-unittests-with-in-memory-sqlite.html>)
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
issue.

*With regards,*
*Rafał Bolanowski*