From: Chris Alfonso Date: Tue, 1 May 2012 15:04:34 +0000 (-0400) Subject: Scoping the session per thread (request). X-Git-Tag: 2014.1~1902 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=dc3c5bdf3db776cbabfce5e2ee3634c2f689f8f6;p=openstack-build%2Fheat-build.git Scoping the session per thread (request). Fixes issue #94 http://docs.sqlalchemy.org/en/rel_0_7/orm/session.html#sqlalchemy.orm.scoped_session --- diff --git a/heat/db/api.py b/heat/db/api.py index 98684139..c5fd544e 100644 --- a/heat/db/api.py +++ b/heat/db/api.py @@ -39,8 +39,6 @@ db_opts = [ help='The backend to use for db'), ] -#conf = config.HeatEngineConfigOpts() -#conf.db_backend = 'heat.db.sqlalchemy.api' IMPL = heat.utils.LazyPluggable('db_backend', sqlalchemy='heat.db.sqlalchemy.api') diff --git a/heat/db/sqlalchemy/session.py b/heat/db/sqlalchemy/session.py index aad0b5c9..9248e40a 100644 --- a/heat/db/sqlalchemy/session.py +++ b/heat/db/sqlalchemy/session.py @@ -106,9 +106,9 @@ def get_engine(): def get_maker(engine, autocommit=True, expire_on_commit=False): """Return a SQLAlchemy sessionmaker using the given engine.""" - return sqlalchemy.orm.sessionmaker(bind=engine, + return sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=engine, autocommit=autocommit, - expire_on_commit=expire_on_commit) + expire_on_commit=expire_on_commit)) def _get_sql_connection():