Cleaned up session management.
This commit is contained in:
1 parent
b19bb5fc7a
commit
a300db9845
4 files changed
+119
-178
No files matched your search
+12
-12
@@ -6,19 +6,19 @@ from sqlalchemy.orm import scoped_session, sessionmaker
|
||||
db = SQLAlchemy()
|
||||
|
||||
@contextmanager
|
||||
def session_scope(engine):
|
||||
if engine:
|
||||
session = scoped_session(sessionmaker(autocommit = False, autoflush = False, bind = engine))
|
||||
#Base.query = session.query_property()
|
||||
def session_scope():
|
||||
#session = scoped_session(sessionmaker(autocommit = False, autoflush = False, bind = engine))
|
||||
session = db.session
|
||||
#Base.query = session.query_property()
|
||||
|
||||
try:
|
||||
yield session
|
||||
session.commit()
|
||||
except:
|
||||
session.rollback()
|
||||
raise
|
||||
finally:
|
||||
session.close()
|
||||
try:
|
||||
yield session
|
||||
session.commit()
|
||||
except:
|
||||
session.rollback()
|
||||
raise
|
||||
finally:
|
||||
session.close()
|
||||
|
||||
import pkgutil
|
||||
|
||||
|
||||
Reference in new issue
Block a user