changeset 6638:cfbc0d6860ca

sqlalchemy: be consistent, always use Session() instead of just Session
author domruf <dominikruf@gmail.com>
date Tue, 09 May 2017 21:29:17 +0200
parents a32ca3200ca7
children 2db16cda05ba
files kallithea/controllers/journal.py kallithea/lib/auth.py kallithea/tests/api/api_base.py kallithea/tests/functional/test_pullrequests.py
diffstat 4 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/journal.py	Sat May 13 03:53:49 2017 +0200
+++ b/kallithea/controllers/journal.py	Tue May 09 21:29:17 2017 +0200
@@ -254,7 +254,7 @@
             try:
                 self.scm_model.toggle_following_user(user_id,
                                             request.authuser.user_id)
-                Session.commit()
+                Session().commit()
                 return 'ok'
             except Exception:
                 log.error(traceback.format_exc())
@@ -265,7 +265,7 @@
             try:
                 self.scm_model.toggle_following_repo(repo_id,
                                             request.authuser.user_id)
-                Session.commit()
+                Session().commit()
                 return 'ok'
             except Exception:
                 log.error(traceback.format_exc())
--- a/kallithea/lib/auth.py	Sat May 13 03:53:49 2017 +0200
+++ b/kallithea/lib/auth.py	Tue May 09 21:29:17 2017 +0200
@@ -43,7 +43,6 @@
 from kallithea import __platform__, is_windows, is_unix
 from kallithea.config.routing import url
 from kallithea.lib.vcs.utils.lazy import LazyProperty
-from kallithea.model import meta
 from kallithea.model.meta import Session
 from kallithea.model.user import UserModel
 from kallithea.model.db import User, Repository, Permission, \
@@ -724,11 +723,10 @@
     """
     log.info('getting information about all available permissions')
     try:
-        sa = meta.Session
-        all_perms = sa.query(Permission).all()
+        all_perms = Session().query(Permission).all()
         config['available_permissions'] = [x.permission_name for x in all_perms]
     finally:
-        meta.Session.remove()
+        Session.remove()
 
 
 #==============================================================================
--- a/kallithea/tests/api/api_base.py	Sat May 13 03:53:49 2017 +0200
+++ b/kallithea/tests/api/api_base.py	Tue May 09 21:29:17 2017 +0200
@@ -278,7 +278,7 @@
         repo_name = u'test_pull'
         r = fixture.create_repo(repo_name, repo_type=self.REPO_TYPE)
         r.clone_uri = os.path.join(Ui.get_by_key('paths', '/').ui_value, self.REPO)
-        Session.commit()
+        Session().commit()
 
         id_, params = _build_data(self.apikey, 'pull',
                                   repoid=repo_name,)
--- a/kallithea/tests/functional/test_pullrequests.py	Sat May 13 03:53:49 2017 +0200
+++ b/kallithea/tests/functional/test_pullrequests.py	Tue May 09 21:29:17 2017 +0200
@@ -296,12 +296,12 @@
         self.repo_name = u'main'
         repo = fixture.create_repo(self.repo_name, repo_type='hg')
         self.repo_scm_instance = repo.scm_instance
-        Session.commit()
+        Session().commit()
         self.c = PullrequestsController()
 
     def teardown_method(self, method):
         fixture.destroy_repo(u'main')
-        Session.commit()
+        Session().commit()
         Session.remove()
 
     def test_repo_refs_empty_repo(self):