Hi,

Using SQLAlchemy 0.7.7 with an underlying sqlite databse, we
configured the engine with poolclass=SingletonThreadPool and
pool_size=50
Our unit-tests were working fine. But when running the app, some
(ProgrammingError) Cannot work on a closed database occured.
Reading the docs and mailist archives, we tried to switch to NullPool
which is the advised poolclass for sqlite.

It broke all our unit-test raising '(OperationalError) no such
table: ...blabla...'

Here after you will find our code. An OrmManager is instancied and we
call the get_session() method on it when we want to make some db
stuff.

Here is the one which makes the unit-test pass but raises an
occasional '(Programming Error): Cannot operate on a closed database'
when running our app:

import sqlite3
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.pool import SingletonThreadPool, NullPool

import centralunit.core.models
import centralunit.core.models.meta

class OrmManager:
    """
    OrmManager class

    Handles the database and provides an abstraction layer for it
    """

    def  __init__(self,  database, metadata,  echo=False):
        self.database = database
        self.session_maker = sessionmaker()
        engine = create_engine('sqlite:///' + database, echo=echo,
                connect_args={'detect_types': sqlite3.PARSE_DECLTYPES|
                              sqlite3.PARSE_COLNAMES},
                native_datetime=True,
                poolclass=SingletonThreadPool,
                pool_size=50
                )

        metadata.create_all(engine)
        self.session_maker.configure(bind=engine)

    def get_session(self):
        """Gets ORM session"""
        return self.session_maker()


and here is the one which makes the unit-test fail but should avoid
the occasional '(Programming Error): Cannot operate on a closed
database' when running our app:

import sqlite3
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.pool import SingletonThreadPool, NullPool, StaticPool

import centralunit.core.models
import centralunit.core.models.meta

class OrmManager:
    """
    OrmManager class

    Handles the database and provides an abstraction layer for it
    """

    def  __init__(self,  database, metadata,  echo=False):
        self.database = database
        self.session_maker = sessionmaker()
        engine = create_engine('sqlite:///' + database, echo=echo,
                connect_args={'detect_types': sqlite3.PARSE_DECLTYPES|
                              sqlite3.PARSE_COLNAMES},
                native_datetime=True,
                poolclass=NullPool,
                )

        metadata.create_all(engine)
        self.session_maker.configure(bind=engine)

    def get_session(self):
        """Gets ORM session"""
        return self.session_maker()

We would like to switch to NullPool... Any idea to avoid the 'no such
table' error ?

Thanks a lot for your help,

Pierre

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to