From 51cc9001052cbefaf809ca5f6bcb5700dc684b45 Mon Sep 17 00:00:00 2001
From: David Trattnig <david.trattnig@o94.at>
Date: Fri, 20 Nov 2020 16:40:23 +0100
Subject: [PATCH] Proper session scoping. #41

---
 src/scheduling/models.py | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/scheduling/models.py b/src/scheduling/models.py
index 89ae33c4..7e0d31ce 100644
--- a/src/scheduling/models.py
+++ b/src/scheduling/models.py
@@ -24,28 +24,27 @@ import datetime
 
 import sqlalchemy as sa
 
-from sqlalchemy                     import BigInteger, Boolean, Column, DateTime, Integer, String, ForeignKey, ColumnDefault
-from sqlalchemy                     import orm
-from sqlalchemy.ext.declarative     import declarative_base
-from sqlalchemy.orm                 import relationship
-from sqlalchemy.ext.hybrid          import hybrid_property
+from sqlalchemy import BigInteger, Boolean, Column, DateTime, Integer, String, ForeignKey, ColumnDefault
+from sqlalchemy.orm import scoped_session
+from sqlalchemy.orm import sessionmaker
+from sqlalchemy.orm import relationship
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.ext.hybrid import hybrid_property
 
-from src.base.config                import AuraConfig
-from src.base.utils                 import SimpleUtil
-from src.core.resources             import ResourceUtil
-
-
-
-# Init Config
-config = AuraConfig()
+from src.base.config import AuraConfig
+from src.base.utils import SimpleUtil
+from src.core.resources import ResourceUtil
 
 # Initialize DB Model and session
+config = AuraConfig()
 engine = sa.create_engine(config.get_database_uri())
 Base = declarative_base()
 Base.metadata.bind = engine
 
 class DB():
-    session = orm.scoped_session(orm.sessionmaker())(bind=engine)
+    session_factory = sessionmaker(bind=engine)
+    Session = scoped_session(session_factory)
+    session = Session()
     Model = Base
 
 
-- 
GitLab