]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Scoping the session per thread (request).
authorChris Alfonso <calfonso@redhat.com>
Tue, 1 May 2012 15:04:34 +0000 (11:04 -0400)
committerChris Alfonso <calfonso@redhat.com>
Tue, 1 May 2012 15:05:48 +0000 (11:05 -0400)
Fixes issue #94
http://docs.sqlalchemy.org/en/rel_0_7/orm/session.html#sqlalchemy.orm.scoped_session

heat/db/api.py
heat/db/sqlalchemy/session.py

index 98684139b3cedec0a9b3b73b08d183fc0b436dcf..c5fd544e50682395f3adff75d3902fb549014039 100644 (file)
@@ -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')
 
index aad0b5c90feebd6482809d22645e1a7c4dc15d93..9248e40acf3835456585d7a3fc92ab454f365df0 100644 (file)
@@ -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():