Commits

Chad Dombrova committed eb6cc73

Change the SqlAlchemyModelInspector._session object from a session instance to a session class

  • Participants
  • Parent commits e5aaad2
  • Branches external_triggers

Comments (0)

Files changed (2)

denormalize/orms/sqlalchemy.py

         if not isinstance(primary_key, tuple):
             primary_key = (primary_key,)
 
-        return self._session.query(self._model).get(primary_key)
+        session = self._session()
+        q = session.query(self._model)
+        return q.get(primary_key)
 
     # FIXME: move to CollectionModel?
     def get_native_objects(self):
-        return self._session.query(self._model).all()
+        session = self._session()
+        return session.query(self._model).all()
 
     # FIXME: move to CollectionModel?
     def get_objects_affected_by(self, filter_paths, model, primary_keys):
                 # primary_keys is a tuple
                 filt.append(prop == primary_keys[i])
 
+        session = self._session()
         queries = []
         for filter_path in filter_paths:
             join_paths = [x.accessor for x in filter_path]
-            q = self._session.query(*select).join(*join_paths)
+            q = session.query(*select).join(*join_paths)
             queries.append(q.filter(*filt))
-        result = self._session.query(distinct(*select)).union(*queries).all()
+        result = session.query(distinct(*select)).union(*queries).all()
 
         return set(result)
 

denormalize/tests/test_sqlalchemy/common.py

 
 # FIXME:
 from denormalize.orms.sqlalchemy import SqlAlchemyModelInspector
-SqlAlchemyModelInspector._session = models.Session()
+SqlAlchemyModelInspector._session = models.Session
 
 
 class ModelTestCase(unittest2.TestCase):