changeset 8686:b095e2fbba44

model: always import whole meta module - also when referencing Session
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 12 Oct 2020 11:21:15 +0200
parents dff9658bdd98
children 5e46f73f0d1c
files kallithea/alembic/env.py kallithea/bin/kallithea_cli_db.py kallithea/bin/kallithea_cli_repo.py kallithea/controllers/admin/auth_settings.py kallithea/controllers/admin/defaults.py kallithea/controllers/admin/gists.py kallithea/controllers/admin/my_account.py kallithea/controllers/admin/permissions.py kallithea/controllers/admin/repo_groups.py kallithea/controllers/admin/repos.py kallithea/controllers/admin/settings.py kallithea/controllers/admin/user_groups.py kallithea/controllers/admin/users.py kallithea/controllers/api/api.py kallithea/controllers/changeset.py kallithea/controllers/journal.py kallithea/controllers/login.py kallithea/controllers/pullrequests.py kallithea/lib/auth.py kallithea/lib/auth_modules/__init__.py kallithea/lib/db_manage.py kallithea/lib/vcs/backends/ssh.py kallithea/model/api_key.py kallithea/model/comment.py kallithea/model/db.py kallithea/model/pull_request.py kallithea/model/ssh_key.py kallithea/model/user.py kallithea/tests/api/api_base.py kallithea/tests/conftest.py kallithea/tests/fixture.py kallithea/tests/functional/test_admin.py kallithea/tests/functional/test_admin_gists.py kallithea/tests/functional/test_admin_repo_groups.py kallithea/tests/functional/test_admin_repos.py kallithea/tests/functional/test_admin_user_groups.py kallithea/tests/functional/test_admin_users.py kallithea/tests/functional/test_changeset_pullrequests_comments.py kallithea/tests/functional/test_compare.py kallithea/tests/functional/test_files.py kallithea/tests/functional/test_forks.py kallithea/tests/functional/test_home.py kallithea/tests/functional/test_login.py kallithea/tests/functional/test_my_account.py kallithea/tests/functional/test_pullrequests.py kallithea/tests/functional/test_pullrequests_git.py kallithea/tests/functional/test_search_indexing.py kallithea/tests/functional/test_summary.py kallithea/tests/models/common.py kallithea/tests/models/test_notifications.py kallithea/tests/models/test_permissions.py kallithea/tests/models/test_repo_groups.py kallithea/tests/models/test_repos.py kallithea/tests/models/test_settings.py kallithea/tests/models/test_user_group_permissions_on_repo_groups.py kallithea/tests/models/test_user_groups.py kallithea/tests/models/test_user_permissions_on_repo_groups.py kallithea/tests/models/test_users.py kallithea/tests/other/test_validators.py kallithea/tests/other/test_vcs_operations.py
diffstat 60 files changed, 507 insertions(+), 510 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/alembic/env.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/alembic/env.py	Mon Oct 12 11:21:15 2020 +0200
@@ -21,7 +21,7 @@
 from alembic import context
 from sqlalchemy import engine_from_config, pool
 
-from kallithea.model import db
+from kallithea.model import meta
 
 
 # The alembic.config.Config object, which wraps the current .ini file.
@@ -93,7 +93,7 @@
 
             # Support autogeneration of migration scripts based on "diff" between
             # current database schema and kallithea.model.db schema.
-            target_metadata=db.Base.metadata,
+            target_metadata=meta.Base.metadata,
             include_object=include_in_autogeneration,
             render_as_batch=True, # batch mode is needed for SQLite support
         )
--- a/kallithea/bin/kallithea_cli_db.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/bin/kallithea_cli_db.py	Mon Oct 12 11:21:15 2020 +0200
@@ -16,7 +16,7 @@
 import kallithea
 import kallithea.bin.kallithea_cli_base as cli_base
 from kallithea.lib.db_manage import DbManage
-from kallithea.model.meta import Session
+from kallithea.model import meta
 
 
 @cli_base.register_command(needs_config_file=True, config_file_initialize_app=True)
@@ -67,7 +67,7 @@
         dbmanage.create_admin_user()
         dbmanage.create_permissions()
         dbmanage.populate_default_permissions()
-        Session().commit()
+        meta.Session().commit()
 
     else:  # then called again after app initialization
         added, _ = kallithea.lib.utils.repo2db_mapper(kallithea.model.scm.ScmModel().repo_scan())
--- a/kallithea/bin/kallithea_cli_repo.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/bin/kallithea_cli_repo.py	Mon Oct 12 11:21:15 2020 +0200
@@ -30,8 +30,8 @@
 import kallithea.bin.kallithea_cli_base as cli_base
 from kallithea.lib.utils import REMOVED_REPO_PAT, repo2db_mapper
 from kallithea.lib.utils2 import ask_ok
+from kallithea.model import meta
 from kallithea.model.db import Repository
-from kallithea.model.meta import Session
 from kallithea.model.scm import ScmModel
 
 
@@ -86,7 +86,7 @@
         # first access
         repo.set_invalidate()
 
-    Session().commit()
+    meta.Session().commit()
 
     click.echo('Updated database with information about latest change in the following %s repositories:' % (len(repo_list)))
     click.echo('\n'.join(repo.repo_name for repo in repo_list))
--- a/kallithea/controllers/admin/auth_settings.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/auth_settings.py	Mon Oct 12 11:21:15 2020 +0200
@@ -37,9 +37,9 @@
 from kallithea.lib.auth import HasPermissionAnyDecorator, LoginRequired
 from kallithea.lib.base import BaseController, render
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import Setting
 from kallithea.model.forms import AuthSettingsForm
-from kallithea.model.meta import Session
 
 
 log = logging.getLogger(__name__)
@@ -132,7 +132,7 @@
                     v = ','.join(v)
                 log.debug("%s = %s", k, str(v))
                 setting = Setting.create_or_update(k, v)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Auth settings updated successfully'),
                        category='success')
         except formencode.Invalid as errors:
--- a/kallithea/controllers/admin/defaults.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/defaults.py	Mon Oct 12 11:21:15 2020 +0200
@@ -38,9 +38,9 @@
 from kallithea.lib.auth import HasPermissionAnyDecorator, LoginRequired
 from kallithea.lib.base import BaseController, render
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import Setting
 from kallithea.model.forms import DefaultsForm
-from kallithea.model.meta import Session
 
 
 log = logging.getLogger(__name__)
@@ -70,7 +70,7 @@
             form_result = _form.to_python(dict(request.POST))
             for k, v in form_result.items():
                 setting = Setting.create_or_update(k, v)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Default settings updated successfully'),
                     category='success')
 
--- a/kallithea/controllers/admin/gists.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/gists.py	Mon Oct 12 11:21:15 2020 +0200
@@ -42,10 +42,10 @@
 from kallithea.lib.utils2 import safe_int, safe_str, time_to_datetime
 from kallithea.lib.vcs.exceptions import NodeNotChangedError, VCSError
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import Gist
 from kallithea.model.forms import GistForm
 from kallithea.model.gist import GistModel
-from kallithea.model.meta import Session
 
 
 log = logging.getLogger(__name__)
@@ -129,7 +129,7 @@
                 gist_type=gist_type,
                 lifetime=form_result['lifetime']
             )
-            Session().commit()
+            meta.Session().commit()
             new_gist_id = gist.gist_access_id
         except formencode.Invalid as errors:
             defaults = errors.value
@@ -159,7 +159,7 @@
         owner = gist.owner_id == request.authuser.user_id
         if h.HasPermissionAny('hg.admin')() or owner:
             GistModel().delete(gist)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Deleted gist %s') % gist.gist_access_id, category='success')
         else:
             raise HTTPForbidden()
@@ -232,12 +232,12 @@
                     lifetime=rpost['lifetime']
                 )
 
-                Session().commit()
+                meta.Session().commit()
                 h.flash(_('Successfully updated gist content'), category='success')
             except NodeNotChangedError:
                 # raised if nothing was changed in repo itself. We anyway then
                 # store only DB stuff for gist
-                Session().commit()
+                meta.Session().commit()
                 h.flash(_('Successfully updated gist data'), category='success')
             except Exception:
                 log.error(traceback.format_exc())
--- a/kallithea/controllers/admin/my_account.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/my_account.py	Mon Oct 12 11:21:15 2020 +0200
@@ -41,10 +41,10 @@
 from kallithea.lib.base import BaseController, IfSshEnabled, render
 from kallithea.lib.utils2 import generate_api_key, safe_int
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.api_key import ApiKeyModel
 from kallithea.model.db import Repository, User, UserEmailMap, UserFollowing
 from kallithea.model.forms import PasswordChangeForm, UserForm
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 from kallithea.model.ssh_key import SshKeyModel, SshKeyModelException
 from kallithea.model.user import UserModel
@@ -69,13 +69,13 @@
     def _load_my_repos_data(self, watched=False):
         if watched:
             admin = False
-            repos_list = Session().query(Repository) \
+            repos_list = meta.Session().query(Repository) \
                          .join(UserFollowing) \
                          .filter(UserFollowing.user_id ==
                                  request.authuser.user_id).all()
         else:
             admin = True
-            repos_list = Session().query(Repository) \
+            repos_list = meta.Session().query(Repository) \
                          .filter(Repository.owner_id ==
                                  request.authuser.user_id).all()
 
@@ -113,7 +113,7 @@
                                    skip_attrs=skip_attrs)
                 h.flash(_('Your account was updated successfully'),
                         category='success')
-                Session().commit()
+                meta.Session().commit()
                 update = True
 
             except formencode.Invalid as errors:
@@ -148,7 +148,7 @@
             try:
                 form_result = _form.to_python(request.POST)
                 UserModel().update(request.authuser.user_id, form_result)
-                Session().commit()
+                meta.Session().commit()
                 h.flash(_("Successfully updated password"), category='success')
             except formencode.Invalid as errors:
                 return htmlfill.render(
@@ -200,7 +200,7 @@
 
         try:
             UserModel().add_extra_email(request.authuser.user_id, email)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_("Added email %s to user") % email, category='success')
         except formencode.Invalid as error:
             msg = error.error_dict['email']
@@ -215,7 +215,7 @@
         email_id = request.POST.get('del_email_id')
         user_model = UserModel()
         user_model.delete_extra_email(request.authuser.user_id, email_id)
-        Session().commit()
+        meta.Session().commit()
         h.flash(_("Removed email from user"), category='success')
         raise HTTPFound(location=url('my_account_emails'))
 
@@ -239,7 +239,7 @@
         lifetime = safe_int(request.POST.get('lifetime'), -1)
         description = request.POST.get('description')
         ApiKeyModel().create(request.authuser.user_id, description, lifetime)
-        Session().commit()
+        meta.Session().commit()
         h.flash(_("API key successfully created"), category='success')
         raise HTTPFound(location=url('my_account_api_keys'))
 
@@ -248,11 +248,11 @@
         if request.POST.get('del_api_key_builtin'):
             user = User.get(request.authuser.user_id)
             user.api_key = generate_api_key()
-            Session().commit()
+            meta.Session().commit()
             h.flash(_("API key successfully reset"), category='success')
         elif api_key:
             ApiKeyModel().delete(api_key, request.authuser.user_id)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_("API key successfully deleted"), category='success')
 
         raise HTTPFound(location=url('my_account_api_keys'))
@@ -271,7 +271,7 @@
         try:
             new_ssh_key = SshKeyModel().create(request.authuser.user_id,
                                                description, public_key)
-            Session().commit()
+            meta.Session().commit()
             SshKeyModel().write_authorized_keys()
             h.flash(_("SSH key %s successfully added") % new_ssh_key.fingerprint, category='success')
         except SshKeyModelException as e:
@@ -283,7 +283,7 @@
         fingerprint = request.POST.get('del_public_key_fingerprint')
         try:
             SshKeyModel().delete(fingerprint, request.authuser.user_id)
-            Session().commit()
+            meta.Session().commit()
             SshKeyModel().write_authorized_keys()
             h.flash(_("SSH key successfully deleted"), category='success')
         except SshKeyModelException as e:
--- a/kallithea/controllers/admin/permissions.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/permissions.py	Mon Oct 12 11:21:15 2020 +0200
@@ -40,9 +40,9 @@
 from kallithea.lib.auth import AuthUser, HasPermissionAnyDecorator, LoginRequired
 from kallithea.lib.base import BaseController, render
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import User, UserIpMap
 from kallithea.model.forms import DefaultPermissionsForm
-from kallithea.model.meta import Session
 from kallithea.model.permission import PermissionModel
 
 
@@ -113,7 +113,7 @@
                 form_result = _form.to_python(dict(request.POST))
                 form_result.update({'perm_user_name': 'default'})
                 PermissionModel().update(form_result)
-                Session().commit()
+                meta.Session().commit()
                 h.flash(_('Global permissions updated successfully'),
                         category='success')
 
--- a/kallithea/controllers/admin/repo_groups.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/repo_groups.py	Mon Oct 12 11:21:15 2020 +0200
@@ -41,9 +41,9 @@
 from kallithea.lib.base import BaseController, render
 from kallithea.lib.utils2 import safe_int
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import RepoGroup, Repository
 from kallithea.model.forms import RepoGroupForm, RepoGroupPermsForm
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.model.scm import AvailableRepoGroupChoices, RepoGroupList
@@ -150,7 +150,7 @@
                 owner=request.authuser.user_id, # TODO: make editable
                 copy_permissions=form_result['group_copy_permissions']
             )
-            Session().commit()
+            meta.Session().commit()
             # TODO: in future action_logger(, '', '', '')
         except formencode.Invalid as errors:
             return htmlfill.render(
@@ -215,7 +215,7 @@
             form_result = repo_group_form.to_python(dict(request.POST))
 
             new_gr = RepoGroupModel().update(group_name, form_result)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Updated repository group %s')
                     % form_result['group_name'], category='success')
             # we now have new name !
@@ -254,7 +254,7 @@
 
         try:
             RepoGroupModel().delete(group_name)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Removed repository group %s') % group_name,
                     category='success')
             # TODO: in future action_logger(, '', '', '')
@@ -358,7 +358,7 @@
         # TODO: implement this
         #action_logger(request.authuser, 'admin_changed_repo_permissions',
         #              repo_name, request.ip_addr)
-        Session().commit()
+        meta.Session().commit()
         h.flash(_('Repository group permissions updated'), category='success')
         raise HTTPFound(location=url('edit_repo_group_perms', group_name=group_name))
 
@@ -388,7 +388,7 @@
                                                    obj_type='user_group',
                                                    recursive=recursive)
 
-            Session().commit()
+            meta.Session().commit()
         except Exception:
             log.error(traceback.format_exc())
             h.flash(_('An error occurred during revoking of permission'),
--- a/kallithea/controllers/admin/repos.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/repos.py	Mon Oct 12 11:21:15 2020 +0200
@@ -45,9 +45,9 @@
 from kallithea.lib.utils2 import safe_int
 from kallithea.lib.vcs import RepositoryError
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import RepoGroup, Repository, RepositoryField, Setting, UserFollowing
 from kallithea.model.forms import RepoFieldForm, RepoForm, RepoPermsForm
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 from kallithea.model.scm import AvailableRepoGroupChoices, RepoList, ScmModel
 
@@ -226,7 +226,7 @@
             changed_name = repo.repo_name
             action_logger(request.authuser, 'admin_updated_repo',
                 changed_name, request.ip_addr)
-            Session().commit()
+            meta.Session().commit()
         except formencode.Invalid as errors:
             log.info(errors)
             defaults = self.__load_data()
@@ -268,7 +268,7 @@
                 repo_name, request.ip_addr)
             ScmModel().mark_for_invalidation(repo_name)
             h.flash(_('Deleted repository %s') % repo_name, category='success')
-            Session().commit()
+            meta.Session().commit()
         except AttachedForksError:
             h.flash(_('Cannot delete repository %s which still has forks')
                         % repo_name, category='warning')
@@ -314,7 +314,7 @@
         # TODO: implement this
         #action_logger(request.authuser, 'admin_changed_repo_permissions',
         #              repo_name, request.ip_addr)
-        Session().commit()
+        meta.Session().commit()
         h.flash(_('Repository permissions updated'), category='success')
         raise HTTPFound(location=url('edit_repo_perms', repo_name=repo_name))
 
@@ -341,7 +341,7 @@
             # TODO: implement this
             #action_logger(request.authuser, 'admin_revoked_repo_permissions',
             #              repo_name, request.ip_addr)
-            Session().commit()
+            meta.Session().commit()
         except Exception:
             log.error(traceback.format_exc())
             h.flash(_('An error occurred during revoking of permission'),
@@ -371,8 +371,8 @@
             new_field.field_value = form_result['new_field_value']  # set initial blank value
             new_field.field_desc = form_result['new_field_desc']
             new_field.field_label = form_result['new_field_label']
-            Session().add(new_field)
-            Session().commit()
+            meta.Session().add(new_field)
+            meta.Session().commit()
         except formencode.Invalid as e:
             h.flash(_('Field validation error: %s') % e.msg, category='error')
         except Exception as e:
@@ -384,8 +384,8 @@
     def delete_repo_field(self, repo_name, field_id):
         field = RepositoryField.get_or_404(field_id)
         try:
-            Session().delete(field)
-            Session().commit()
+            meta.Session().delete(field)
+            meta.Session().commit()
         except Exception as e:
             log.error(traceback.format_exc())
             msg = _('An error occurred during removal of field')
@@ -436,7 +436,7 @@
             self.scm_model.toggle_following_repo(repo_id, user_id)
             h.flash(_('Updated repository visibility in public journal'),
                     category='success')
-            Session().commit()
+            meta.Session().commit()
         except Exception:
             h.flash(_('An error occurred during setting this'
                       ' repository in public journal'),
@@ -455,7 +455,7 @@
             repo = ScmModel().mark_as_fork(repo_name, fork_id,
                                            request.authuser.username)
             fork = repo.fork.repo_name if repo.fork else _('Nothing')
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Marked repository %s as fork of %s') % (repo_name, fork),
                     category='success')
         except RepositoryError as e:
@@ -506,7 +506,7 @@
         if request.POST:
             try:
                 RepoModel().delete_stats(repo_name)
-                Session().commit()
+                meta.Session().commit()
             except Exception as e:
                 log.error(traceback.format_exc())
                 h.flash(_('An error occurred during deletion of repository stats'),
--- a/kallithea/controllers/admin/settings.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/settings.py	Mon Oct 12 11:21:15 2020 +0200
@@ -43,9 +43,9 @@
 from kallithea.lib.utils2 import safe_str
 from kallithea.lib.vcs import VCSError
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import Repository, Setting, Ui
 from kallithea.model.forms import ApplicationSettingsForm, ApplicationUiSettingsForm, ApplicationVisualisationForm
-from kallithea.model.meta import Session
 from kallithea.model.notification import EmailNotificationModel
 from kallithea.model.scm import ScmModel
 
@@ -112,7 +112,7 @@
 #                sett = Ui.get_or_create('extensions', 'hggit')
 #                sett.ui_active = form_result['extensions_hggit']
 
-                Session().commit()
+                meta.Session().commit()
 
                 h.flash(_('Updated VCS settings'), category='success')
 
@@ -204,7 +204,7 @@
                 ):
                     Setting.create_or_update(setting, form_result[setting])
 
-                Session().commit()
+                meta.Session().commit()
                 set_app_settings(config)
                 h.flash(_('Updated application settings'), category='success')
 
@@ -258,7 +258,7 @@
                 for setting, form_key, type_ in settings:
                     Setting.create_or_update(setting, form_result[form_key], type_)
 
-                Session().commit()
+                meta.Session().commit()
                 set_app_settings(config)
                 h.flash(_('Updated visualisation settings'),
                         category='success')
@@ -340,7 +340,7 @@
                         h.flash(_('Added new hook'), category='success')
                     elif hook_id:
                         Ui.delete(hook_id)
-                        Session().commit()
+                        meta.Session().commit()
 
                     # check for edits
                     update = False
@@ -354,7 +354,7 @@
 
                     if update:
                         h.flash(_('Updated hooks'), category='success')
-                    Session().commit()
+                    meta.Session().commit()
                 except Exception:
                     log.error(traceback.format_exc())
                     h.flash(_('Error occurred during hook creation'),
--- a/kallithea/controllers/admin/user_groups.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/user_groups.py	Mon Oct 12 11:21:15 2020 +0200
@@ -44,9 +44,9 @@
 from kallithea.lib.utils import action_logger
 from kallithea.lib.utils2 import safe_int, safe_str
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import User, UserGroup, UserGroupRepoGroupToPerm, UserGroupRepoToPerm, UserGroupToPerm
 from kallithea.model.forms import CustomDefaultPermissionsForm, UserGroupForm, UserGroupPermsForm
-from kallithea.model.meta import Session
 from kallithea.model.scm import UserGroupList
 from kallithea.model.user_group import UserGroupModel
 
@@ -132,7 +132,7 @@
                           None, request.ip_addr)
             h.flash(h.HTML(_('Created user group %s')) % h.link_to(gr, url('edit_users_group', id=ug.users_group_id)),
                 category='success')
-            Session().commit()
+            meta.Session().commit()
         except formencode.Invalid as errors:
             return htmlfill.render(
                 render('admin/user_groups/user_group_add.html'),
@@ -172,7 +172,7 @@
                           'admin_updated_users_group:%s' % gr,
                           None, request.ip_addr)
             h.flash(_('Updated user group %s') % gr, category='success')
-            Session().commit()
+            meta.Session().commit()
         except formencode.Invalid as errors:
             ug_model = UserGroupModel()
             defaults = errors.value
@@ -203,7 +203,7 @@
         usr_gr = UserGroup.get_or_404(id)
         try:
             UserGroupModel().delete(usr_gr)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Successfully deleted user group'), category='success')
         except UserGroupsAssignedException as e:
             h.flash(e, category='error')
@@ -270,7 +270,7 @@
         # TODO: implement this
         #action_logger(request.authuser, 'admin_changed_repo_permissions',
         #              repo_name, request.ip_addr)
-        Session().commit()
+        meta.Session().commit()
         h.flash(_('User group permissions updated'), category='success')
         raise HTTPFound(location=url('edit_user_group_perms', id=id))
 
@@ -295,7 +295,7 @@
             elif obj_type == 'user_group':
                 UserGroupModel().revoke_user_group_permission(target_user_group=id,
                                                               user_group=obj_id)
-            Session().commit()
+            meta.Session().commit()
         except Exception:
             log.error(traceback.format_exc())
             h.flash(_('An error occurred during revoking of permission'),
@@ -365,7 +365,7 @@
                 .filter(UserGroupToPerm.users_group == user_group) \
                 .all()
             for ug in defs:
-                Session().delete(ug)
+                meta.Session().delete(ug)
 
             if form_result['create_repo_perm']:
                 usergroup_model.grant_perm(id, 'hg.create.repository')
@@ -381,7 +381,7 @@
                 usergroup_model.grant_perm(id, 'hg.fork.none')
 
             h.flash(_("Updated permissions"), category='success')
-            Session().commit()
+            meta.Session().commit()
         except Exception:
             log.error(traceback.format_exc())
             h.flash(_('An error occurred during permissions saving'),
--- a/kallithea/controllers/admin/users.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/admin/users.py	Mon Oct 12 11:21:15 2020 +0200
@@ -45,10 +45,10 @@
 from kallithea.lib.utils import action_logger
 from kallithea.lib.utils2 import datetime_to_time, generate_api_key, safe_int
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.api_key import ApiKeyModel
 from kallithea.model.db import User, UserEmailMap, UserIpMap, UserToPerm
 from kallithea.model.forms import CustomDefaultPermissionsForm, UserForm
-from kallithea.model.meta import Session
 from kallithea.model.ssh_key import SshKeyModel, SshKeyModelException
 from kallithea.model.user import UserModel
 
@@ -119,7 +119,7 @@
                           None, request.ip_addr)
             h.flash(_('Created user %s') % user.username,
                     category='success')
-            Session().commit()
+            meta.Session().commit()
         except formencode.Invalid as errors:
             return htmlfill.render(
                 render('admin/users/user_add.html'),
@@ -157,7 +157,7 @@
             action_logger(request.authuser, 'admin_updated_user:%s' % usr,
                           None, request.ip_addr)
             h.flash(_('User updated successfully'), category='success')
-            Session().commit()
+            meta.Session().commit()
         except formencode.Invalid as errors:
             defaults = errors.value
             e = errors.error_dict or {}
@@ -184,7 +184,7 @@
         has_ssh_keys = bool(usr.ssh_keys)
         try:
             UserModel().delete(usr)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Successfully deleted user'), category='success')
         except (UserOwnsReposException, DefaultUserException) as e:
             h.flash(e, category='warning')
@@ -268,7 +268,7 @@
         lifetime = safe_int(request.POST.get('lifetime'), -1)
         description = request.POST.get('description')
         ApiKeyModel().create(c.user.user_id, description, lifetime)
-        Session().commit()
+        meta.Session().commit()
         h.flash(_("API key successfully created"), category='success')
         raise HTTPFound(location=url('edit_user_api_keys', id=c.user.user_id))
 
@@ -278,11 +278,11 @@
         api_key = request.POST.get('del_api_key')
         if request.POST.get('del_api_key_builtin'):
             c.user.api_key = generate_api_key()
-            Session().commit()
+            meta.Session().commit()
             h.flash(_("API key successfully reset"), category='success')
         elif api_key:
             ApiKeyModel().delete(api_key, c.user.user_id)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_("API key successfully deleted"), category='success')
 
         raise HTTPFound(location=url('edit_user_api_keys', id=c.user.user_id))
@@ -322,7 +322,7 @@
                 .filter(UserToPerm.user == user) \
                 .all()
             for ug in defs:
-                Session().delete(ug)
+                meta.Session().delete(ug)
 
             if form_result['create_repo_perm']:
                 user_model.grant_perm(id, 'hg.create.repository')
@@ -337,7 +337,7 @@
             else:
                 user_model.grant_perm(id, 'hg.fork.none')
             h.flash(_("Updated permissions"), category='success')
-            Session().commit()
+            meta.Session().commit()
         except Exception:
             log.error(traceback.format_exc())
             h.flash(_('An error occurred during permissions saving'),
@@ -364,7 +364,7 @@
 
         try:
             user_model.add_extra_email(id, email)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_("Added email %s to user") % email, category='success')
         except formencode.Invalid as error:
             msg = error.error_dict['email']
@@ -380,7 +380,7 @@
         email_id = request.POST.get('del_email_id')
         user_model = UserModel()
         user_model.delete_extra_email(id, email_id)
-        Session().commit()
+        meta.Session().commit()
         h.flash(_("Removed email from user"), category='success')
         raise HTTPFound(location=url('edit_user_emails', id=id))
 
@@ -406,7 +406,7 @@
 
         try:
             user_model.add_extra_ip(id, ip)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_("Added IP address %s to user whitelist") % ip, category='success')
         except formencode.Invalid as error:
             msg = error.error_dict['ip']
@@ -424,7 +424,7 @@
         ip_id = request.POST.get('del_ip_id')
         user_model = UserModel()
         user_model.delete_extra_ip(id, ip_id)
-        Session().commit()
+        meta.Session().commit()
         h.flash(_("Removed IP address from user whitelist"), category='success')
 
         if 'default_user' in request.POST:
@@ -452,7 +452,7 @@
         try:
             new_ssh_key = SshKeyModel().create(c.user.user_id,
                                                description, public_key)
-            Session().commit()
+            meta.Session().commit()
             SshKeyModel().write_authorized_keys()
             h.flash(_("SSH key %s successfully added") % new_ssh_key.fingerprint, category='success')
         except SshKeyModelException as e:
@@ -466,7 +466,7 @@
         fingerprint = request.POST.get('del_public_key_fingerprint')
         try:
             SshKeyModel().delete(fingerprint, c.user.user_id)
-            Session().commit()
+            meta.Session().commit()
             SshKeyModel().write_authorized_keys()
             h.flash(_("SSH key successfully deleted"), category='success')
         except SshKeyModelException as e:
--- a/kallithea/controllers/api/api.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/api/api.py	Mon Oct 12 11:21:15 2020 +0200
@@ -38,11 +38,11 @@
 from kallithea.lib.utils import action_logger, repo2db_mapper
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.exceptions import EmptyRepositoryError
+from kallithea.model import meta
 from kallithea.model.changeset_status import ChangesetStatusModel
 from kallithea.model.comment import ChangesetCommentsModel
 from kallithea.model.db import ChangesetStatus, Gist, Permission, PullRequest, RepoGroup, Repository, Setting, User, UserGroup, UserIpMap
 from kallithea.model.gist import GistModel
-from kallithea.model.meta import Session
 from kallithea.model.pull_request import PullRequestModel
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
@@ -501,7 +501,7 @@
                 extern_type=extern_type,
                 extern_name=extern_name
             )
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='created new user `%s`' % username,
                 user=user.get_api_data()
@@ -579,7 +579,7 @@
             store_update(updates, extern_type, 'extern_type')
 
             user = UserModel().update_user(user, **updates)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='updated user ID:%s %s' % (user.user_id, user.username),
                 user=user.get_api_data()
@@ -622,7 +622,7 @@
 
         try:
             UserModel().delete(userid)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='deleted user ID:%s %s' % (user.user_id, user.username),
                 user=None
@@ -732,7 +732,7 @@
             owner = get_user_or_error(owner)
             ug = UserGroupModel().create(name=group_name, description=description,
                                          owner=owner, active=active)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='created new user group `%s`' % group_name,
                 user_group=ug.get_api_data()
@@ -793,7 +793,7 @@
         store_update(updates, active, 'users_group_active')
         try:
             UserGroupModel().update(user_group, updates)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='updated user group ID:%s %s' % (user_group.users_group_id,
                                                      user_group.users_group_name),
@@ -839,7 +839,7 @@
 
         try:
             UserGroupModel().delete(user_group)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='deleted user group ID:%s %s' %
                     (user_group.users_group_id, user_group.users_group_name),
@@ -900,7 +900,7 @@
                 user.username, user_group.users_group_name
             )
             msg = msg if success else 'User is already in that group'
-            Session().commit()
+            meta.Session().commit()
 
             return dict(
                 success=success,
@@ -948,7 +948,7 @@
                 user.username, user_group.users_group_name
             )
             msg = msg if success else "User wasn't in group"
-            Session().commit()
+            meta.Session().commit()
             return dict(success=success, msg=msg)
         except Exception:
             log.error(traceback.format_exc())
@@ -1339,7 +1339,7 @@
             store_update(updates, enable_downloads, 'repo_enable_downloads')
 
             RepoModel().update(repo, **updates)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='updated repo ID:%s %s' % (repo.repo_id, repo.repo_name),
                 repository=repo.get_api_data()
@@ -1503,7 +1503,7 @@
                 )
 
             RepoModel().delete(repo, forks=forks)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='Deleted repository `%s`%s' % (repo.repo_name, _forks_msg),
                 success=True
@@ -1544,7 +1544,7 @@
 
             RepoModel().grant_user_permission(repo=repo, user=user, perm=perm)
 
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='Granted perm: `%s` for user: `%s` in repo: `%s`' % (
                     perm.permission_name, user.username, repo.repo_name
@@ -1584,7 +1584,7 @@
         user = get_user_or_error(userid)
         try:
             RepoModel().revoke_user_permission(repo=repo, user=user)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='Revoked perm for user: `%s` in repo: `%s`' % (
                     user.username, repo.repo_name
@@ -1646,7 +1646,7 @@
             RepoModel().grant_user_group_permission(
                 repo=repo, group_name=user_group, perm=perm)
 
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='Granted perm: `%s` for user group: `%s` in '
                     'repo: `%s`' % (
@@ -1696,7 +1696,7 @@
             RepoModel().revoke_user_group_permission(
                 repo=repo, group_name=user_group)
 
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='Revoked perm for user group: `%s` in repo: `%s`' % (
                     user_group.users_group_name, repo.repo_name
@@ -1815,7 +1815,7 @@
                 parent=parent_group,
                 copy_permissions=copy_permissions
             )
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='created new repo group `%s`' % group_name,
                 repo_group=repo_group.get_api_data()
@@ -1839,7 +1839,7 @@
             store_update(updates, owner, 'owner')
             store_update(updates, parent, 'parent_group')
             repo_group = RepoGroupModel().update(repo_group, updates)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='updated repository group ID:%s %s' % (repo_group.group_id,
                                                            repo_group.group_name),
@@ -1879,7 +1879,7 @@
 
         try:
             RepoGroupModel().delete(repo_group)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='deleted repo group ID:%s %s' %
                     (repo_group.group_id, repo_group.group_name),
@@ -1942,7 +1942,7 @@
                                             obj_type="user",
                                             perm=perm,
                                             recursive=apply_to_children)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='Granted perm: `%s` (recursive:%s) for user: `%s` in repo group: `%s`' % (
                     perm.permission_name, apply_to_children, user.username, repo_group.name
@@ -2003,7 +2003,7 @@
                                                obj_type="user",
                                                recursive=apply_to_children)
 
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='Revoked perm (recursive:%s) for user: `%s` in repo group: `%s`' % (
                     apply_to_children, user.username, repo_group.name
@@ -2072,7 +2072,7 @@
                                             obj_type="user_group",
                                             perm=perm,
                                             recursive=apply_to_children)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='Granted perm: `%s` (recursive:%s) for user group: `%s` in repo group: `%s`' % (
                     perm.permission_name, apply_to_children,
@@ -2139,7 +2139,7 @@
                                                obj=user_group,
                                                obj_type="user_group",
                                                recursive=apply_to_children)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='Revoked perm (recursive:%s) for user group: `%s` in repo group: `%s`' % (
                     apply_to_children, user_group.users_group_name, repo_group.name
@@ -2246,7 +2246,7 @@
                                       gist_mapping=files,
                                       gist_type=gist_type,
                                       lifetime=lifetime)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='created new gist',
                 gist=gist.get_api_data()
@@ -2288,7 +2288,7 @@
 
         try:
             GistModel().delete(gist)
-            Session().commit()
+            meta.Session().commit()
             return dict(
                 msg='deleted gist ID:%s' % (gist.gist_access_id,),
                 gist=None
@@ -2394,7 +2394,7 @@
             action_logger(apiuser,
                           'user_closed_pull_request:%s' % pull_request_id,
                           pull_request.org_repo, request.ip_addr)
-        Session().commit()
+        meta.Session().commit()
         return True
 
     # permission check inside
@@ -2434,7 +2434,7 @@
         if remove_objs:
             PullRequestModel().remove_reviewers(apiuser, pull_request, remove_objs)
 
-        Session().commit()
+        meta.Session().commit()
 
         return {
             'added': [x.username for x in new_reviewers],
--- a/kallithea/controllers/changeset.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/changeset.py	Mon Oct 12 11:21:15 2020 +0200
@@ -44,10 +44,10 @@
 from kallithea.lib.utils2 import ascii_str, safe_str
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError
+from kallithea.model import meta
 from kallithea.model.changeset_status import ChangesetStatusModel
 from kallithea.model.comment import ChangesetCommentsModel
 from kallithea.model.db import ChangesetComment, ChangesetStatus
-from kallithea.model.meta import Session
 from kallithea.model.pull_request import PullRequestModel
 
 
@@ -97,7 +97,7 @@
             h.HasRepoPermissionLevel('admin')(pull_request.other_repo.repo_name)
         ) and not pull_request.is_closed():
             PullRequestModel().delete(pull_request)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Successfully deleted pull request %s') % pull_request_id,
                     category='success')
             return {
@@ -141,7 +141,7 @@
                       'user_closed_pull_request:%s' % pull_request_id,
                       c.db_repo, request.ip_addr)
 
-    Session().commit()
+    meta.Session().commit()
 
     data = {
        'target_id': h.safeid(request.POST.get('f_path')),
@@ -167,7 +167,7 @@
     repo_admin = h.HasRepoPermissionLevel('admin')(repo_name)
     if h.HasPermissionAny('hg.admin')() or repo_admin or owner:
         ChangesetCommentsModel().delete(comment=co)
-        Session().commit()
+        meta.Session().commit()
         return True
     else:
         raise HTTPForbidden()
--- a/kallithea/controllers/journal.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/journal.py	Mon Oct 12 11:21:15 2020 +0200
@@ -43,8 +43,8 @@
 from kallithea.lib.base import BaseController, render
 from kallithea.lib.page import Page
 from kallithea.lib.utils2 import AttributeDict, safe_int
+from kallithea.model import meta
 from kallithea.model.db import Repository, User, UserFollowing, UserLog
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 
 
@@ -215,7 +215,7 @@
             try:
                 self.scm_model.toggle_following_user(user_id,
                                             request.authuser.user_id)
-                Session().commit()
+                meta.Session().commit()
                 return 'ok'
             except Exception:
                 log.error(traceback.format_exc())
@@ -226,7 +226,7 @@
             try:
                 self.scm_model.toggle_following_repo(repo_id,
                                             request.authuser.user_id)
-                Session().commit()
+                meta.Session().commit()
                 return 'ok'
             except Exception:
                 log.error(traceback.format_exc())
--- a/kallithea/controllers/login.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/login.py	Mon Oct 12 11:21:15 2020 +0200
@@ -41,9 +41,9 @@
 from kallithea.lib.base import BaseController, log_in_user, render
 from kallithea.lib.exceptions import UserCreationError
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import Setting, User
 from kallithea.model.forms import LoginForm, PasswordResetConfirmationForm, PasswordResetRequestForm, RegisterForm
-from kallithea.model.meta import Session
 from kallithea.model.user import UserModel
 
 
@@ -147,7 +147,7 @@
                 UserModel().create_registration(form_result)
                 h.flash(_('You have successfully registered with %s') % (c.site_name or 'Kallithea'),
                         category='success')
-                Session().commit()
+                meta.Session().commit()
                 raise HTTPFound(location=url('login_home'))
 
             except formencode.Invalid as errors:
--- a/kallithea/controllers/pullrequests.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/controllers/pullrequests.py	Mon Oct 12 11:21:15 2020 +0200
@@ -45,11 +45,11 @@
 from kallithea.lib.utils2 import ascii_bytes, safe_bytes, safe_int
 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.changeset_status import ChangesetStatusModel
 from kallithea.model.comment import ChangesetCommentsModel
 from kallithea.model.db import ChangesetStatus, PullRequest, PullRequestReviewer, Repository, User
 from kallithea.model.forms import PullRequestForm, PullRequestPostForm
-from kallithea.model.meta import Session
 from kallithea.model.pull_request import CreatePullRequestAction, CreatePullRequestIterationAction, PullRequestModel
 
 
@@ -339,7 +339,7 @@
 
         try:
             pull_request = cmd.execute()
-            Session().commit()
+            meta.Session().commit()
         except Exception:
             h.flash(_('Error occurred while creating pull request'),
                     category='error')
@@ -362,7 +362,7 @@
 
         try:
             pull_request = cmd.execute()
-            Session().commit()
+            meta.Session().commit()
         except Exception:
             h.flash(_('Error occurred while creating pull request'),
                     category='error')
@@ -425,7 +425,7 @@
         PullRequestModel().add_reviewers(user, pull_request, added_reviewers)
         PullRequestModel().remove_reviewers(user, pull_request, removed_reviewers)
 
-        Session().commit()
+        meta.Session().commit()
         h.flash(_('Pull request updated'), category='success')
 
         raise HTTPFound(location=pull_request.url())
@@ -438,7 +438,7 @@
         # only owner can delete it !
         if pull_request.owner_id == request.authuser.user_id:
             PullRequestModel().delete(pull_request)
-            Session().commit()
+            meta.Session().commit()
             h.flash(_('Successfully deleted pull request'),
                     category='success')
             raise HTTPFound(location=url('my_pullrequests'))
--- a/kallithea/lib/auth.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/lib/auth.py	Mon Oct 12 11:21:15 2020 +0200
@@ -44,9 +44,9 @@
 from kallithea.lib.utils2 import ascii_bytes, ascii_str, safe_bytes
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 from kallithea.lib.webutils import url
+from kallithea.model import meta
 from kallithea.model.db import (Permission, UserApiKeys, UserGroup, UserGroupMember, UserGroupRepoGroupToPerm, UserGroupRepoToPerm, UserGroupToPerm,
                                 UserGroupUserGroupToPerm, UserIpMap, UserToPerm)
-from kallithea.model.meta import Session
 from kallithea.model.user import UserModel
 
 
@@ -232,7 +232,7 @@
             global_permissions.add(perm.permission.permission_name)
 
         # user group global permissions
-        user_perms_from_users_groups = Session().query(UserGroupToPerm) \
+        user_perms_from_users_groups = meta.Session().query(UserGroupToPerm) \
             .options(joinedload(UserGroupToPerm.permission)) \
             .join((UserGroupMember, UserGroupToPerm.users_group_id ==
                    UserGroupMember.users_group_id)) \
@@ -252,7 +252,7 @@
                 global_permissions.add(perm.permission.permission_name)
 
         # user specific global permissions
-        user_perms = Session().query(UserToPerm) \
+        user_perms = meta.Session().query(UserToPerm) \
                 .options(joinedload(UserToPerm.permission)) \
                 .filter(UserToPerm.user_id == self.user_id).all()
         for perm in user_perms:
@@ -291,7 +291,7 @@
 
             # user group repository permissions
             user_repo_perms_from_users_groups = \
-             Session().query(UserGroupRepoToPerm) \
+             meta.Session().query(UserGroupRepoToPerm) \
                 .join((UserGroup, UserGroupRepoToPerm.users_group_id ==
                        UserGroup.users_group_id)) \
                 .filter(UserGroup.users_group_active == True) \
@@ -337,7 +337,7 @@
 
             # user group for repo groups permissions
             user_repo_group_perms_from_users_groups = \
-                Session().query(UserGroupRepoGroupToPerm) \
+                meta.Session().query(UserGroupRepoGroupToPerm) \
                 .join((UserGroup, UserGroupRepoGroupToPerm.users_group_id ==
                        UserGroup.users_group_id)) \
                 .filter(UserGroup.users_group_active == True) \
@@ -382,7 +382,7 @@
 
             # user group for user group permissions
             user_group_user_groups_perms = \
-                Session().query(UserGroupUserGroupToPerm) \
+                meta.Session().query(UserGroupUserGroupToPerm) \
                 .join((UserGroup, UserGroupUserGroupToPerm.target_user_group_id
                        == UserGroup.users_group_id)) \
                 .join((UserGroupMember, UserGroupUserGroupToPerm.user_group_id
--- a/kallithea/lib/auth_modules/__init__.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/lib/auth_modules/__init__.py	Mon Oct 12 11:21:15 2020 +0200
@@ -23,9 +23,8 @@
 from kallithea.lib.auth import AuthUser, PasswordGenerator
 from kallithea.lib.compat import hybrid_property
 from kallithea.lib.utils2 import asbool
-from kallithea.model import validators
+from kallithea.model import meta, validators
 from kallithea.model.db import Setting, User
-from kallithea.model.meta import Session
 from kallithea.model.user import UserModel
 from kallithea.model.user_group import UserGroupModel
 
@@ -267,7 +266,7 @@
             # created from plugins. We store this info in _group_data JSON field
             groups = user_data['groups'] or []
             UserGroupModel().enforce_groups(user, groups, self.name)
-            Session().commit()
+            meta.Session().commit()
         return user_data
 
 
--- a/kallithea/lib/db_manage.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/lib/db_manage.py	Mon Oct 12 11:21:15 2020 +0200
@@ -38,9 +38,9 @@
 from sqlalchemy.engine import create_engine
 
 from kallithea.lib.utils2 import ask_ok
+from kallithea.model import meta
 from kallithea.model.base import init_model
 from kallithea.model.db import Repository, Setting, Ui, User
-from kallithea.model.meta import Base, Session
 from kallithea.model.permission import PermissionModel
 from kallithea.model.user import UserModel
 
@@ -70,7 +70,7 @@
             # init new sessions
             engine = create_engine(self.dburi)
             init_model(engine)
-            self.sa = Session()
+            self.sa = meta.Session()
 
     def create_tables(self, reuse_database=False):
         """
@@ -91,7 +91,7 @@
             sys.exit(0)
 
         if reuse_database:
-            Base.metadata.drop_all()
+            meta.Base.metadata.drop_all()
         else:
             if url.drivername == 'mysql':
                 url.database = None  # don't connect to the database (it might not exist)
@@ -110,9 +110,9 @@
             else:
                 # Some databases enforce foreign key constraints and Base.metadata.drop_all() doesn't work, but this is
                 # known to work on SQLite - possibly not on other databases with strong referential integrity
-                Base.metadata.drop_all()
+                meta.Base.metadata.drop_all()
 
-        Base.metadata.create_all(checkfirst=False)
+        meta.Base.metadata.create_all(checkfirst=False)
 
         # Create an Alembic configuration and generate the version table,
         # "stamping" it with the most recent Alembic migration revision, to
@@ -303,7 +303,7 @@
         if self.cli_args.get('public_access') is False:
             log.info('Public access disabled')
             user.active = False
-            Session().commit()
+            meta.Session().commit()
 
     def create_permissions(self):
         """
--- a/kallithea/lib/vcs/backends/ssh.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/lib/vcs/backends/ssh.py	Mon Oct 12 11:21:15 2020 +0200
@@ -25,8 +25,8 @@
 
 from kallithea.lib.auth import AuthUser, HasPermissionAnyMiddleware
 from kallithea.lib.utils2 import set_hook_environment
+from kallithea.model import meta
 from kallithea.model.db import Repository, User, UserSshKeys
-from kallithea.model.meta import Session
 
 
 log = logging.getLogger(__name__)
@@ -74,7 +74,7 @@
         if ssh_key is None:
             self.exit('SSH key %r not found' % key_id)
         ssh_key.last_seen = datetime.datetime.now()
-        Session().commit()
+        meta.Session().commit()
 
         if HasPermissionAnyMiddleware('repository.write',
                                       'repository.admin')(self.authuser, self.repo_name):
--- a/kallithea/model/api_key.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/model/api_key.py	Mon Oct 12 11:21:15 2020 +0200
@@ -29,8 +29,8 @@
 import time
 
 from kallithea.lib.utils2 import generate_api_key
+from kallithea.model import meta
 from kallithea.model.db import User, UserApiKeys
-from kallithea.model.meta import Session
 
 
 log = logging.getLogger(__name__)
@@ -51,7 +51,7 @@
         new_api_key.user_id = user.user_id
         new_api_key.description = description
         new_api_key.expires = time.time() + (lifetime * 60) if lifetime != -1 else -1
-        Session().add(new_api_key)
+        meta.Session().add(new_api_key)
 
         return new_api_key
 
@@ -67,7 +67,7 @@
             api_key = api_key.filter(UserApiKeys.user_id == user.user_id)
 
         api_key = api_key.scalar()
-        Session().delete(api_key)
+        meta.Session().delete(api_key)
 
     def get_api_keys(self, user, show_expired=True):
         user = User.guess_instance(user)
--- a/kallithea/model/comment.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/model/comment.py	Mon Oct 12 11:21:15 2020 +0200
@@ -32,8 +32,8 @@
 
 from kallithea.lib import helpers as h
 from kallithea.lib.utils import extract_mentioned_users
+from kallithea.model import meta
 from kallithea.model.db import ChangesetComment, PullRequest, Repository, User
-from kallithea.model.meta import Session
 from kallithea.model.notification import NotificationModel
 
 
@@ -41,13 +41,13 @@
 
 
 def _list_changeset_commenters(revision):
-    return (Session().query(User)
+    return (meta.Session().query(User)
         .join(ChangesetComment.author)
         .filter(ChangesetComment.revision == revision)
         .all())
 
 def _list_pull_request_commenters(pull_request):
-    return (Session().query(User)
+    return (meta.Session().query(User)
         .join(ChangesetComment.author)
         .filter(ChangesetComment.pull_request_id == pull_request.pull_request_id)
         .all())
@@ -193,8 +193,8 @@
         else:
             raise Exception('Please specify revision or pull_request_id')
 
-        Session().add(comment)
-        Session().flush()
+        meta.Session().add(comment)
+        meta.Session().flush()
 
         if send_email:
             (subj, body, recipients, notification_type,
@@ -230,7 +230,7 @@
 
     def delete(self, comment):
         comment = ChangesetComment.guess_instance(comment)
-        Session().delete(comment)
+        meta.Session().delete(comment)
 
         return comment
 
@@ -270,7 +270,7 @@
         if inline is None and f_path is not None:
             raise Exception("f_path only makes sense for inline comments.")
 
-        q = Session().query(ChangesetComment)
+        q = meta.Session().query(ChangesetComment)
 
         if inline:
             if f_path is not None:
--- a/kallithea/model/db.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/model/db.py	Mon Oct 12 11:21:15 2020 +0200
@@ -50,7 +50,7 @@
 from kallithea.lib.vcs import get_backend
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.utils.helpers import get_scm
-from kallithea.model.meta import Base, Session
+from kallithea.model import meta
 
 
 log = logging.getLogger(__name__)
@@ -107,7 +107,7 @@
 
     @classmethod
     def query(cls):
-        return Session().query(cls)
+        return meta.Session().query(cls)
 
     @classmethod
     def get(cls, id_):
@@ -157,7 +157,7 @@
     @classmethod
     def delete(cls, id_):
         obj = cls.query().get(id_)
-        Session().delete(obj)
+        meta.Session().delete(obj)
 
     def __repr__(self):
         return '<DB:%s>' % (self.__class__.__name__)
@@ -168,7 +168,7 @@
                             'sqlite_autoincrement': True,
                            }
 
-class Setting(Base, BaseDbModel):
+class Setting(meta.Base, BaseDbModel):
     __tablename__ = 'settings'
     __table_args__ = (
         _table_args_default_dict,
@@ -257,7 +257,7 @@
             val = val if val is not None else ''
             type = type if type is not None else 'unicode'
             res = cls(key, val, type)
-            Session().add(res)
+            meta.Session().add(res)
         else:
             if val is not None:
                 # update if set
@@ -321,7 +321,7 @@
         return info
 
 
-class Ui(Base, BaseDbModel):
+class Ui(meta.Base, BaseDbModel):
     __tablename__ = 'ui'
     __table_args__ = (
         Index('ui_ui_section_ui_key_idx', 'ui_section', 'ui_key'),
@@ -349,7 +349,7 @@
         setting = cls.get_by_key(section, key)
         if setting is None:
             setting = cls(ui_section=section, ui_key=key)
-            Session().add(setting)
+            meta.Session().add(setting)
         return setting
 
     @classmethod
@@ -384,7 +384,7 @@
             self.ui_section, self.ui_key, self.ui_value)
 
 
-class User(Base, BaseDbModel):
+class User(meta.Base, BaseDbModel):
     __tablename__ = 'users'
     __table_args__ = (
         Index('u_username_idx', 'username'),
@@ -664,7 +664,7 @@
         return data
 
 
-class UserApiKeys(Base, BaseDbModel):
+class UserApiKeys(meta.Base, BaseDbModel):
     __tablename__ = 'user_api_keys'
     __table_args__ = (
         Index('uak_api_key_idx', 'api_key'),
@@ -686,7 +686,7 @@
         return (self.expires != -1) & (time.time() > self.expires)
 
 
-class UserEmailMap(Base, BaseDbModel):
+class UserEmailMap(meta.Base, BaseDbModel):
     __tablename__ = 'user_email_map'
     __table_args__ = (
         Index('uem_email_idx', 'email'),
@@ -701,7 +701,7 @@
     @validates('_email')
     def validate_email(self, key, email):
         # check if this email is not main one
-        main_email = Session().query(User).filter(User.email == email).scalar()
+        main_email = meta.Session().query(User).filter(User.email == email).scalar()
         if main_email is not None:
             raise AttributeError('email %s is present is user table' % email)
         return email
@@ -715,7 +715,7 @@
         self._email = val.lower() if val else None
 
 
-class UserIpMap(Base, BaseDbModel):
+class UserIpMap(meta.Base, BaseDbModel):
     __tablename__ = 'user_ip_map'
     __table_args__ = (
         UniqueConstraint('user_id', 'ip_addr'),
@@ -743,7 +743,7 @@
         return "<%s %s: %s>" % (self.__class__.__name__, self.user_id, self.ip_addr)
 
 
-class UserLog(Base, BaseDbModel):
+class UserLog(meta.Base, BaseDbModel):
     __tablename__ = 'user_logs'
     __table_args__ = (
         _table_args_default_dict,
@@ -771,7 +771,7 @@
     repository = relationship('Repository', cascade='')
 
 
-class UserGroup(Base, BaseDbModel):
+class UserGroup(meta.Base, BaseDbModel):
     __tablename__ = 'users_groups'
     __table_args__ = (
         _table_args_default_dict,
@@ -852,7 +852,7 @@
         return data
 
 
-class UserGroupMember(Base, BaseDbModel):
+class UserGroupMember(meta.Base, BaseDbModel):
     __tablename__ = 'users_groups_members'
     __table_args__ = (
         _table_args_default_dict,
@@ -870,7 +870,7 @@
         self.user_id = u_id
 
 
-class RepositoryField(Base, BaseDbModel):
+class RepositoryField(meta.Base, BaseDbModel):
     __tablename__ = 'repositories_fields'
     __table_args__ = (
         UniqueConstraint('repository_id', 'field_key'),  # no-multi field
@@ -908,7 +908,7 @@
         return row
 
 
-class Repository(Base, BaseDbModel):
+class Repository(meta.Base, BaseDbModel):
     __tablename__ = 'repositories'
     __table_args__ = (
         Index('r_repo_name_idx', 'repo_name'),
@@ -1035,9 +1035,9 @@
         """Get the repo, defaulting to database case sensitivity.
         case_insensitive will be slower and should only be specified if necessary."""
         if case_insensitive:
-            q = Session().query(cls).filter(sqlalchemy.func.lower(cls.repo_name) == sqlalchemy.func.lower(repo_name))
+            q = meta.Session().query(cls).filter(sqlalchemy.func.lower(cls.repo_name) == sqlalchemy.func.lower(repo_name))
         else:
-            q = Session().query(cls).filter(cls.repo_name == repo_name)
+            q = meta.Session().query(cls).filter(cls.repo_name == repo_name)
         q = q.options(joinedload(Repository.fork)) \
                 .options(joinedload(Repository.owner)) \
                 .options(joinedload(Repository.group))
@@ -1248,7 +1248,7 @@
                       self.repo_name, cs_cache)
             self.updated_on = last_change
             self.changeset_cache = cs_cache
-            Session().commit()
+            meta.Session().commit()
         else:
             log.debug('changeset_cache for %s already up to date with %s',
                       self.repo_name, cs_cache['raw_id'])
@@ -1357,7 +1357,7 @@
         )
 
 
-class RepoGroup(Base, BaseDbModel):
+class RepoGroup(meta.Base, BaseDbModel):
     __tablename__ = 'groups'
     __table_args__ = (
         _table_args_default_dict,
@@ -1526,7 +1526,7 @@
         return data
 
 
-class Permission(Base, BaseDbModel):
+class Permission(meta.Base, BaseDbModel):
     __tablename__ = 'permissions'
     __table_args__ = (
         Index('p_perm_name_idx', 'permission_name'),
@@ -1633,7 +1633,7 @@
 
     @classmethod
     def get_default_perms(cls, default_user_id):
-        q = Session().query(UserRepoToPerm) \
+        q = meta.Session().query(UserRepoToPerm) \
          .options(joinedload(UserRepoToPerm.repository)) \
          .options(joinedload(UserRepoToPerm.permission)) \
          .filter(UserRepoToPerm.user_id == default_user_id)
@@ -1642,7 +1642,7 @@
 
     @classmethod
     def get_default_group_perms(cls, default_user_id):
-        q = Session().query(UserRepoGroupToPerm) \
+        q = meta.Session().query(UserRepoGroupToPerm) \
          .options(joinedload(UserRepoGroupToPerm.group)) \
          .options(joinedload(UserRepoGroupToPerm.permission)) \
          .filter(UserRepoGroupToPerm.user_id == default_user_id)
@@ -1651,7 +1651,7 @@
 
     @classmethod
     def get_default_user_group_perms(cls, default_user_id):
-        q = Session().query(UserUserGroupToPerm) \
+        q = meta.Session().query(UserUserGroupToPerm) \
          .options(joinedload(UserUserGroupToPerm.user_group)) \
          .options(joinedload(UserUserGroupToPerm.permission)) \
          .filter(UserUserGroupToPerm.user_id == default_user_id)
@@ -1659,7 +1659,7 @@
         return q.all()
 
 
-class UserRepoToPerm(Base, BaseDbModel):
+class UserRepoToPerm(meta.Base, BaseDbModel):
     __tablename__ = 'repo_to_perm'
     __table_args__ = (
         UniqueConstraint('user_id', 'repository_id', 'permission_id'),
@@ -1681,7 +1681,7 @@
         n.user = user
         n.repository = repository
         n.permission = permission
-        Session().add(n)
+        meta.Session().add(n)
         return n
 
     def __repr__(self):
@@ -1689,7 +1689,7 @@
             self.__class__.__name__, self.user, self.repository, self.permission)
 
 
-class UserUserGroupToPerm(Base, BaseDbModel):
+class UserUserGroupToPerm(meta.Base, BaseDbModel):
     __tablename__ = 'user_user_group_to_perm'
     __table_args__ = (
         UniqueConstraint('user_id', 'user_group_id', 'permission_id'),
@@ -1711,7 +1711,7 @@
         n.user = user
         n.user_group = user_group
         n.permission = permission
-        Session().add(n)
+        meta.Session().add(n)
         return n
 
     def __repr__(self):
@@ -1719,7 +1719,7 @@
             self.__class__.__name__, self.user, self.user_group, self.permission)
 
 
-class UserToPerm(Base, BaseDbModel):
+class UserToPerm(meta.Base, BaseDbModel):
     __tablename__ = 'user_to_perm'
     __table_args__ = (
         UniqueConstraint('user_id', 'permission_id'),
@@ -1738,7 +1738,7 @@
             self.__class__.__name__, self.user, self.permission)
 
 
-class UserGroupRepoToPerm(Base, BaseDbModel):
+class UserGroupRepoToPerm(meta.Base, BaseDbModel):
     __tablename__ = 'users_group_repo_to_perm'
     __table_args__ = (
         UniqueConstraint('repository_id', 'users_group_id', 'permission_id'),
@@ -1760,7 +1760,7 @@
         n.users_group = users_group
         n.repository = repository
         n.permission = permission
-        Session().add(n)
+        meta.Session().add(n)
         return n
 
     def __repr__(self):
@@ -1768,7 +1768,7 @@
             self.__class__.__name__, self.users_group, self.repository, self.permission)
 
 
-class UserGroupUserGroupToPerm(Base, BaseDbModel):
+class UserGroupUserGroupToPerm(meta.Base, BaseDbModel):
     __tablename__ = 'user_group_user_group_to_perm'
     __table_args__ = (
         UniqueConstraint('target_user_group_id', 'user_group_id', 'permission_id'),
@@ -1790,7 +1790,7 @@
         n.target_user_group = target_user_group
         n.user_group = user_group
         n.permission = permission
-        Session().add(n)
+        meta.Session().add(n)
         return n
 
     def __repr__(self):
@@ -1798,7 +1798,7 @@
             self.__class__.__name__, self.user_group, self.target_user_group, self.permission)
 
 
-class UserGroupToPerm(Base, BaseDbModel):
+class UserGroupToPerm(meta.Base, BaseDbModel):
     __tablename__ = 'users_group_to_perm'
     __table_args__ = (
         UniqueConstraint('users_group_id', 'permission_id',),
@@ -1813,7 +1813,7 @@
     permission = relationship('Permission')
 
 
-class UserRepoGroupToPerm(Base, BaseDbModel):
+class UserRepoGroupToPerm(meta.Base, BaseDbModel):
     __tablename__ = 'user_repo_group_to_perm'
     __table_args__ = (
         UniqueConstraint('user_id', 'group_id', 'permission_id'),
@@ -1835,11 +1835,11 @@
         n.user = user
         n.group = repository_group
         n.permission = permission
-        Session().add(n)
+        meta.Session().add(n)
         return n
 
 
-class UserGroupRepoGroupToPerm(Base, BaseDbModel):
+class UserGroupRepoGroupToPerm(meta.Base, BaseDbModel):
     __tablename__ = 'users_group_repo_group_to_perm'
     __table_args__ = (
         UniqueConstraint('users_group_id', 'group_id'),
@@ -1861,11 +1861,11 @@
         n.users_group = user_group
         n.group = repository_group
         n.permission = permission
-        Session().add(n)
+        meta.Session().add(n)
         return n
 
 
-class Statistics(Base, BaseDbModel):
+class Statistics(meta.Base, BaseDbModel):
     __tablename__ = 'statistics'
     __table_args__ = (
          _table_args_default_dict,
@@ -1881,7 +1881,7 @@
     repository = relationship('Repository', single_parent=True)
 
 
-class UserFollowing(Base, BaseDbModel):
+class UserFollowing(meta.Base, BaseDbModel):
     __tablename__ = 'user_followings'
     __table_args__ = (
         UniqueConstraint('user_id', 'follows_repository_id', name='uq_user_followings_user_repo'),
@@ -1905,7 +1905,7 @@
         return cls.query().filter(cls.follows_repository_id == repo_id)
 
 
-class ChangesetComment(Base, BaseDbModel):
+class ChangesetComment(meta.Base, BaseDbModel):
     __tablename__ = 'changeset_comments'
     __table_args__ = (
         Index('cc_revision_idx', 'revision'),
@@ -1952,7 +1952,7 @@
         return self.created_on > datetime.datetime.now() - datetime.timedelta(minutes=5)
 
 
-class ChangesetStatus(Base, BaseDbModel):
+class ChangesetStatus(meta.Base, BaseDbModel):
     __tablename__ = 'changeset_statuses'
     __table_args__ = (
         Index('cs_revision_idx', 'revision'),
@@ -2015,7 +2015,7 @@
             )
 
 
-class PullRequest(Base, BaseDbModel):
+class PullRequest(meta.Base, BaseDbModel):
     __tablename__ = 'pull_requests'
     __table_args__ = (
         Index('pr_org_repo_id_idx', 'org_repo_id'),
@@ -2157,7 +2157,7 @@
                      pull_request_id=self.pull_request_id, **kwargs)
 
 
-class PullRequestReviewer(Base, BaseDbModel):
+class PullRequestReviewer(meta.Base, BaseDbModel):
     __tablename__ = 'pull_request_reviewers'
     __table_args__ = (
         Index('pull_request_reviewers_user_id_idx', 'user_id'),
@@ -2189,7 +2189,7 @@
     __tablename__ = 'user_to_notification'
 
 
-class Gist(Base, BaseDbModel):
+class Gist(meta.Base, BaseDbModel):
     __tablename__ = 'gists'
     __table_args__ = (
         Index('g_gist_access_id_idx', 'gist_access_id'),
@@ -2276,7 +2276,7 @@
         return get_repo(os.path.join(gist_base_path, self.gist_access_id))
 
 
-class UserSshKeys(Base, BaseDbModel):
+class UserSshKeys(meta.Base, BaseDbModel):
     __tablename__ = 'user_ssh_keys'
     __table_args__ = (
         Index('usk_fingerprint_idx', 'fingerprint'),
--- a/kallithea/model/pull_request.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/model/pull_request.py	Mon Oct 12 11:21:15 2020 +0200
@@ -36,8 +36,8 @@
 from kallithea.lib.hooks import log_create_pullrequest
 from kallithea.lib.utils import extract_mentioned_users
 from kallithea.lib.utils2 import ascii_bytes
+from kallithea.model import meta
 from kallithea.model.db import ChangesetStatus, PullRequest, PullRequestReviewer, User
-from kallithea.model.meta import Session
 from kallithea.model.notification import NotificationModel
 
 
@@ -74,7 +74,7 @@
         log.debug('Adding reviewers to pull request %s: %s', pr.pull_request_id, reviewers)
         for reviewer in reviewers:
             prr = PullRequestReviewer(reviewer, pr)
-            Session().add(prr)
+            meta.Session().add(prr)
 
         # notification to reviewers
         pr_url = pr.url(canonical=True)
@@ -150,7 +150,7 @@
 
     def delete(self, pull_request):
         pull_request = PullRequest.guess_instance(pull_request)
-        Session().delete(pull_request)
+        meta.Session().delete(pull_request)
         if pull_request.org_repo.scm_instance.alias == 'git':
             # remove a ref under refs/pull/ so that commits can be garbage-collected
             try:
@@ -265,8 +265,8 @@
         pr.title = self.title
         pr.description = self.description
         pr.owner = self.owner
-        Session().add(pr)
-        Session().flush() # make database assign pull_request_id
+        meta.Session().add(pr)
+        meta.Session().flush() # make database assign pull_request_id
 
         if self.org_repo.scm_instance.alias == 'git':
             # create a ref under refs/pull/ so that commits don't get garbage-collected
--- a/kallithea/model/ssh_key.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/model/ssh_key.py	Mon Oct 12 11:21:15 2020 +0200
@@ -31,8 +31,8 @@
 from kallithea.lib import ssh
 from kallithea.lib.utils2 import asbool
 from kallithea.lib.vcs.exceptions import RepositoryError
+from kallithea.model import meta
 from kallithea.model.db import User, UserSshKeys
-from kallithea.model.meta import Session
 
 
 log = logging.getLogger(__name__)
@@ -69,7 +69,7 @@
             raise SshKeyModelException(_('SSH key %s is already used by %s') %
                                        (new_ssh_key.fingerprint, ssh_key.user.username))
 
-        Session().add(new_ssh_key)
+        meta.Session().add(new_ssh_key)
 
         return new_ssh_key
 
@@ -86,7 +86,7 @@
         ssh_key = ssh_key.scalar()
         if ssh_key is None:
             raise SshKeyModelException(_('SSH key with fingerprint %r found') % fingerprint)
-        Session().delete(ssh_key)
+        meta.Session().delete(ssh_key)
 
     def get_ssh_keys(self, user):
         user = User.guess_instance(user)
--- a/kallithea/model/user.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/model/user.py	Mon Oct 12 11:21:15 2020 +0200
@@ -38,8 +38,8 @@
 
 from kallithea.lib.exceptions import DefaultUserException, UserOwnsReposException
 from kallithea.lib.utils2 import generate_api_key, get_current_authuser
+from kallithea.model import meta
 from kallithea.model.db import Permission, User, UserEmailMap, UserIpMap, UserToPerm
-from kallithea.model.meta import Session
 
 
 log = logging.getLogger(__name__)
@@ -83,8 +83,8 @@
             setattr(new_user, k, v)
 
         new_user.api_key = generate_api_key()
-        Session().add(new_user)
-        Session().flush() # make database assign new_user.user_id
+        meta.Session().add(new_user)
+        meta.Session().flush() # make database assign new_user.user_id
 
         log_create_user(new_user.get_dict(), cur_user)
         return new_user
@@ -154,8 +154,8 @@
                     if password else ''
 
             if user is None:
-                Session().add(new_user)
-                Session().flush() # make database assign new_user.user_id
+                meta.Session().add(new_user)
+                meta.Session().flush() # make database assign new_user.user_id
 
             if not edit:
                 log_create_user(new_user.get_dict(), cur_user)
@@ -259,7 +259,7 @@
                 _('User "%s" still owns %s user groups and cannot be '
                   'removed. Switch owners or remove those user groups: %s')
                 % (user.username, len(usergroups), ', '.join(usergroups)))
-        Session().delete(user)
+        meta.Session().delete(user)
 
         from kallithea.lib.hooks import log_delete_user
         log_delete_user(user.get_dict(), cur_user)
@@ -391,7 +391,7 @@
             if not self.can_change_password(user):
                 raise Exception('trying to change password for external user')
             user.password = auth.get_crypt_password(new_passwd)
-            Session().commit()
+            meta.Session().commit()
             log.info('change password for %s', user_email)
         if new_passwd is None:
             raise Exception('unable to set new password')
@@ -429,7 +429,7 @@
         new = UserToPerm()
         new.user = user
         new.permission = perm
-        Session().add(new)
+        meta.Session().add(new)
         return new
 
     def revoke_perm(self, user, perm):
@@ -462,7 +462,7 @@
         obj = UserEmailMap()
         obj.user = user
         obj.email = data['email']
-        Session().add(obj)
+        meta.Session().add(obj)
         return obj
 
     def delete_extra_email(self, user, email_id):
@@ -475,7 +475,7 @@
         user = User.guess_instance(user)
         obj = UserEmailMap.query().get(email_id)
         if obj is not None:
-            Session().delete(obj)
+            meta.Session().delete(obj)
 
     def add_extra_ip(self, user, ip):
         """
@@ -492,7 +492,7 @@
         obj = UserIpMap()
         obj.user = user
         obj.ip_addr = data['ip']
-        Session().add(obj)
+        meta.Session().add(obj)
         return obj
 
     def delete_extra_ip(self, user, ip_id):
@@ -505,4 +505,4 @@
         user = User.guess_instance(user)
         obj = UserIpMap.query().get(ip_id)
         if obj:
-            Session().delete(obj)
+            meta.Session().delete(obj)
--- a/kallithea/tests/api/api_base.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/api/api_base.py	Mon Oct 12 11:21:15 2020 +0200
@@ -26,10 +26,10 @@
 from kallithea.lib import ext_json
 from kallithea.lib.auth import AuthUser
 from kallithea.lib.utils2 import ascii_bytes
+from kallithea.model import meta
 from kallithea.model.changeset_status import ChangesetStatusModel
 from kallithea.model.db import ChangesetStatus, PullRequest, PullRequestReviewer, RepoGroup, Repository, Setting, Ui, User
 from kallithea.model.gist import GistModel
-from kallithea.model.meta import Session
 from kallithea.model.pull_request import PullRequestModel
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
@@ -75,13 +75,13 @@
     gr = fixture.create_user_group(name, cur_user=base.TEST_USER_ADMIN_LOGIN)
     UserGroupModel().add_user_to_group(user_group=gr,
                                        user=base.TEST_USER_ADMIN_LOGIN)
-    Session().commit()
+    meta.Session().commit()
     return gr
 
 
 def make_repo_group(name=TEST_REPO_GROUP):
     gr = fixture.create_repo_group(name, cur_user=base.TEST_USER_ADMIN_LOGIN)
-    Session().commit()
+    meta.Session().commit()
     return gr
 
 
@@ -100,7 +100,7 @@
             firstname='first',
             lastname='last'
         )
-        Session().commit()
+        meta.Session().commit()
         cls.TEST_USER_LOGIN = cls.test_user.username
         cls.apikey_regular = cls.test_user.api_key
 
@@ -259,7 +259,7 @@
         # hack around that clone_uri can't be set to to a local path
         # (as shown by test_api_create_repo_clone_uri_local)
         r.clone_uri = os.path.join(Ui.get_by_key('paths', '/').ui_value, self.REPO)
-        Session().commit()
+        meta.Session().commit()
 
         pre_cached_tip = [repo.get_api_data()['last_changeset']['short_id'] for repo in Repository.query().filter(Repository.repo_name == repo_name)]
 
@@ -432,7 +432,7 @@
                                            password='qweqwe',
                                            email='u232@example.com',
                                            firstname='u1', lastname='u1')
-        Session().commit()
+        meta.Session().commit()
         username = usr.username
         email = usr.email
         usr_id = usr.user_id
@@ -453,7 +453,7 @@
                                            password='qweqwe',
                                            email='u232@example.com',
                                            firstname='u1', lastname='u1')
-        Session().commit()
+        meta.Session().commit()
         username = usr.username
 
         id_, params = _build_data(self.apikey, 'delete_user',
@@ -554,7 +554,7 @@
         RepoModel().grant_user_group_permission(repo=self.REPO,
                                                 group_name=new_group,
                                                 perm='repository.read')
-        Session().commit()
+        meta.Session().commit()
         id_, params = _build_data(self.apikey, 'get_repo',
                                   repoid=self.REPO)
         response = api_call(self, params)
@@ -606,7 +606,7 @@
         RepoModel().grant_user_permission(repo=self.REPO,
                                           user=self.TEST_USER_LOGIN,
                                           perm=grant_perm)
-        Session().commit()
+        meta.Session().commit()
         id_, params = _build_data(self.apikey_regular, 'get_repo',
                                   repoid=self.REPO)
         response = api_call(self, params)
@@ -758,7 +758,7 @@
         RepoModel().grant_user_permission(repo=self.REPO,
                                           user=self.TEST_USER_LOGIN,
                                           perm=grant_perm)
-        Session().commit()
+        meta.Session().commit()
 
         rev = 'tip'
         path = '/'
@@ -851,7 +851,7 @@
 
         # create group before creating repo
         rg = fixture.create_repo_group(repo_group_name)
-        Session().commit()
+        meta.Session().commit()
 
         id_, params = _build_data(self.apikey, 'create_repo',
                                   repo_name=repo_name,
@@ -878,11 +878,11 @@
         top_group = RepoGroup.get_by_group_name(TEST_REPO_GROUP)
         assert top_group
         rg = fixture.create_repo_group(repo_group_basename, parent_group_id=top_group)
-        Session().commit()
+        meta.Session().commit()
         RepoGroupModel().grant_user_permission(repo_group_name,
                                                self.TEST_USER_LOGIN,
                                                'group.none')
-        Session().commit()
+        meta.Session().commit()
 
         id_, params = _build_data(self.apikey_regular, 'create_repo',
                                   repo_name=repo_name,
@@ -1551,7 +1551,7 @@
         gr_name = 'test_group_3'
         gr = fixture.create_user_group(gr_name)
         UserGroupModel().add_user_to_group(gr, user=base.TEST_USER_ADMIN_LOGIN)
-        Session().commit()
+        meta.Session().commit()
         try:
             id_, params = _build_data(self.apikey, 'remove_user_from_user_group',
                                       usergroupid=gr_name,
@@ -1571,7 +1571,7 @@
         gr_name = 'test_group_3'
         gr = fixture.create_user_group(gr_name)
         UserGroupModel().add_user_to_group(gr, user=base.TEST_USER_ADMIN_LOGIN)
-        Session().commit()
+        meta.Session().commit()
         try:
             id_, params = _build_data(self.apikey, 'remove_user_from_user_group',
                                       usergroupid=gr_name,
@@ -1764,7 +1764,7 @@
         RepoModel().grant_user_group_permission(repo=self.REPO,
                                                 group_name=TEST_USER_GROUP,
                                                 perm='repository.read')
-        Session().commit()
+        meta.Session().commit()
         id_, params = _build_data(self.apikey,
                                   'revoke_user_group_permission',
                                   repoid=self.REPO,
@@ -1848,7 +1848,7 @@
             RepoGroupModel().grant_user_permission(TEST_REPO_GROUP,
                                                    self.TEST_USER_LOGIN,
                                                    'group.admin')
-            Session().commit()
+            meta.Session().commit()
 
         id_, params = _build_data(self.apikey_regular,
                                   'grant_user_permission_to_repo_group',
@@ -1906,7 +1906,7 @@
         RepoGroupModel().grant_user_permission(repo_group=TEST_REPO_GROUP,
                                                user=base.TEST_USER_ADMIN_LOGIN,
                                                perm='group.read',)
-        Session().commit()
+        meta.Session().commit()
 
         id_, params = _build_data(self.apikey,
                                   'revoke_user_permission_from_repo_group',
@@ -1940,13 +1940,13 @@
         RepoGroupModel().grant_user_permission(repo_group=TEST_REPO_GROUP,
                                                user=base.TEST_USER_ADMIN_LOGIN,
                                                perm='group.read',)
-        Session().commit()
+        meta.Session().commit()
 
         if grant_admin:
             RepoGroupModel().grant_user_permission(TEST_REPO_GROUP,
                                                    self.TEST_USER_LOGIN,
                                                    'group.admin')
-            Session().commit()
+            meta.Session().commit()
 
         id_, params = _build_data(self.apikey_regular,
                                   'revoke_user_permission_from_repo_group',
@@ -2036,7 +2036,7 @@
             RepoGroupModel().grant_user_permission(TEST_REPO_GROUP,
                                                    self.TEST_USER_LOGIN,
                                                    'group.admin')
-            Session().commit()
+            meta.Session().commit()
 
         id_, params = _build_data(self.apikey_regular,
                                   'grant_user_group_permission_to_repo_group',
@@ -2095,7 +2095,7 @@
         RepoGroupModel().grant_user_group_permission(repo_group=TEST_REPO_GROUP,
                                                      group_name=TEST_USER_GROUP,
                                                      perm='group.read',)
-        Session().commit()
+        meta.Session().commit()
         id_, params = _build_data(self.apikey,
                                   'revoke_user_group_permission_from_repo_group',
                                   repogroupid=TEST_REPO_GROUP,
@@ -2128,13 +2128,13 @@
         RepoGroupModel().grant_user_permission(repo_group=TEST_REPO_GROUP,
                                                user=base.TEST_USER_ADMIN_LOGIN,
                                                perm='group.read',)
-        Session().commit()
+        meta.Session().commit()
 
         if grant_admin:
             RepoGroupModel().grant_user_permission(TEST_REPO_GROUP,
                                                    self.TEST_USER_LOGIN,
                                                    'group.admin')
-            Session().commit()
+            meta.Session().commit()
 
         id_, params = _build_data(self.apikey_regular,
                                   'revoke_user_group_permission_from_repo_group',
@@ -2685,8 +2685,8 @@
         pull_request_id = fixture.create_pullrequest(self, self.REPO, self.TEST_PR_SRC, self.TEST_PR_DST, 'edit reviewer test')
         pullrequest = PullRequest().get(pull_request_id)
         prr = PullRequestReviewer(User.get_by_username(base.TEST_USER_REGULAR2_LOGIN), pullrequest)
-        Session().add(prr)
-        Session().commit()
+        meta.Session().add(prr)
+        meta.Session().commit()
 
         assert User.get_by_username(base.TEST_USER_REGULAR_LOGIN) in pullrequest.get_reviewer_users()
         assert User.get_by_username(base.TEST_USER_REGULAR2_LOGIN) in pullrequest.get_reviewer_users()
@@ -2776,8 +2776,8 @@
         pull_request_id = fixture.create_pullrequest(self, self.REPO, self.TEST_PR_SRC, self.TEST_PR_DST, 'edit reviewer test')
         pullrequest = PullRequest().get(pull_request_id)
         prr = PullRequestReviewer(User.get_by_username(base.TEST_USER_ADMIN_LOGIN), pullrequest)
-        Session().add(prr)
-        Session().commit()
+        meta.Session().add(prr)
+        meta.Session().commit()
         assert User.get_by_username(base.TEST_USER_ADMIN_LOGIN) in pullrequest.get_reviewer_users()
         assert User.get_by_username(base.TEST_USER_REGULAR_LOGIN) in pullrequest.get_reviewer_users()
         assert User.get_by_username(base.TEST_USER_REGULAR2_LOGIN) not in pullrequest.get_reviewer_users()
--- a/kallithea/tests/conftest.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/conftest.py	Mon Oct 12 11:21:15 2020 +0200
@@ -15,8 +15,8 @@
 from kallithea.controllers.root import RootController
 from kallithea.lib import inifile
 from kallithea.lib.utils import repo2db_mapper
+from kallithea.model import meta
 from kallithea.model.db import Setting, User, UserIpMap
-from kallithea.model.meta import Session
 from kallithea.model.scm import ScmModel
 from kallithea.model.user import UserModel
 from kallithea.tests.base import TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, TEST_USER_REGULAR_LOGIN, TESTS_TMP_PATH, invalidate_all_caches
@@ -104,11 +104,11 @@
     yield _create_test_user
     for user_id in test_user_ids:
         UserModel().delete(user_id)
-    Session().commit()
+    meta.Session().commit()
 
 
 def _set_settings(*kvtseq):
-    session = Session()
+    session = meta.Session()
     for kvt in kvtseq:
         assert len(kvt) in (2, 3)
         k = kvt[0]
@@ -127,7 +127,7 @@
         for s in Setting.query().all()]
     yield _set_settings
     # Restore settings.
-    session = Session()
+    session = meta.Session()
     keys = frozenset(k for (k, v, t) in settings_snapshot)
     for s in Setting.query().all():
         if s.app_settings_name not in keys:
@@ -158,7 +158,7 @@
 
     # IP permissions are cached, need to invalidate this cache explicitly
     invalidate_all_caches()
-    session = Session()
+    session = meta.Session()
     session.commit()
 
 
--- a/kallithea/tests/fixture.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/fixture.py	Mon Oct 12 11:21:15 2020 +0200
@@ -30,11 +30,11 @@
 from kallithea.lib.auth import AuthUser
 from kallithea.lib.db_manage import DbManage
 from kallithea.lib.vcs.backends.base import EmptyChangeset
+from kallithea.model import meta
 from kallithea.model.changeset_status import ChangesetStatusModel
 from kallithea.model.comment import ChangesetCommentsModel
 from kallithea.model.db import ChangesetStatus, Gist, RepoGroup, Repository, User, UserGroup
 from kallithea.model.gist import GistModel
-from kallithea.model.meta import Session
 from kallithea.model.pull_request import CreatePullRequestAction  # , CreatePullRequestIterationAction, PullRequestModel
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
@@ -77,13 +77,13 @@
                 anon = User.get_default_user()
                 self._before = anon.active
                 anon.active = status
-                Session().commit()
+                meta.Session().commit()
                 invalidate_all_caches()
 
             def __exit__(self, exc_type, exc_val, exc_tb):
                 anon = User.get_default_user()
                 anon.active = self._before
-                Session().commit()
+                meta.Session().commit()
 
         return context()
 
@@ -165,7 +165,7 @@
         form_data['repo_group'] = repo_group # patch form dict so it can be used directly by model
         cur_user = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN)
         RepoModel().create(form_data, cur_user)
-        Session().commit()
+        meta.Session().commit()
         ScmModel().mark_for_invalidation(name)
         return Repository.get_by_repo_name(name)
 
@@ -183,7 +183,7 @@
 
         owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN)
         RepoModel().create_fork(form_data, cur_user=owner)
-        Session().commit()
+        meta.Session().commit()
         ScmModel().mark_for_invalidation(fork_name)
         r = Repository.get_by_repo_name(fork_name)
         assert r
@@ -191,7 +191,7 @@
 
     def destroy_repo(self, repo_name, **kwargs):
         RepoModel().delete(repo_name, **kwargs)
-        Session().commit()
+        meta.Session().commit()
 
     def create_repo_group(self, name, parent_group_id=None, **kwargs):
         assert '/' not in name, (name, kwargs) # use group_parent_id to make nested groups
@@ -207,13 +207,13 @@
             parent=parent_group_id,
             owner=kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN),
             )
-        Session().commit()
+        meta.Session().commit()
         gr = RepoGroup.get_by_group_name(gr.group_name)
         return gr
 
     def destroy_repo_group(self, repogroupid):
         RepoGroupModel().delete(repogroupid)
-        Session().commit()
+        meta.Session().commit()
 
     def create_user(self, name, **kwargs):
         if 'skip_if_exists' in kwargs:
@@ -223,13 +223,13 @@
                 return user
         form_data = self._get_user_create_params(name, **kwargs)
         user = UserModel().create(form_data)
-        Session().commit()
+        meta.Session().commit()
         user = User.get_by_username(user.username)
         return user
 
     def destroy_user(self, userid):
         UserModel().delete(userid)
-        Session().commit()
+        meta.Session().commit()
 
     def create_user_group(self, name, **kwargs):
         if 'skip_if_exists' in kwargs:
@@ -244,13 +244,13 @@
             description=form_data['user_group_description'],
             owner=owner, active=form_data['users_group_active'],
             group_data=form_data['user_group_data'])
-        Session().commit()
+        meta.Session().commit()
         user_group = UserGroup.get_by_group_name(user_group.users_group_name)
         return user_group
 
     def destroy_user_group(self, usergroupid):
         UserGroupModel().delete(user_group=usergroupid, force=True)
-        Session().commit()
+        meta.Session().commit()
 
     def create_gist(self, **kwargs):
         form_data = {
@@ -266,7 +266,7 @@
             gist_mapping=form_data['gist_mapping'], gist_type=form_data['gist_type'],
             lifetime=form_data['lifetime']
         )
-        Session().commit()
+        meta.Session().commit()
 
         return gist
 
@@ -277,7 +277,7 @@
                     GistModel().delete(g)
             else:
                 GistModel().delete(g)
-        Session().commit()
+        meta.Session().commit()
 
     def load_resource(self, resource_name, strip=True):
         with open(os.path.join(FIXTURES, resource_name), 'rb') as f:
@@ -327,7 +327,7 @@
     def review_changeset(self, repo, revision, status, author=TEST_USER_ADMIN_LOGIN):
         comment = ChangesetCommentsModel().create("review comment", repo, author, revision=revision, send_email=False)
         csm = ChangesetStatusModel().set_status(repo, ChangesetStatus.STATUS_APPROVED, author, comment, revision=revision)
-        Session().commit()
+        meta.Session().commit()
         return csm
 
     def create_pullrequest(self, testcontroller, repo_name, pr_src_rev, pr_dst_rev, title='title'):
@@ -342,7 +342,7 @@
             with mock.patch.object(helpers, 'url', (lambda arg, qualified=False, **kwargs: ('https://localhost' if qualified else '') + '/fake/' + arg)):
                 cmd = CreatePullRequestAction(org_repo, other_repo, org_ref, other_ref, title, 'No description', owner_user, reviewers)
                 pull_request = cmd.execute()
-            Session().commit()
+            meta.Session().commit()
         return pull_request.pull_request_id
 
 
@@ -381,7 +381,7 @@
     dbmanage.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL, False)
     dbmanage.create_permissions()
     dbmanage.populate_default_permissions()
-    Session().commit()
+    meta.Session().commit()
     # PART TWO make test repo
     log.debug('making test vcs repositories')
 
--- a/kallithea/tests/functional/test_admin.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_admin.py	Mon Oct 12 11:21:15 2020 +0200
@@ -3,8 +3,8 @@
 import os
 from os.path import dirname
 
+from kallithea.model import meta
 from kallithea.model.db import UserLog
-from kallithea.model.meta import Session
 from kallithea.tests import base
 
 
@@ -16,7 +16,7 @@
     @classmethod
     def setup_class(cls):
         UserLog.query().delete()
-        Session().commit()
+        meta.Session().commit()
 
         def strptime(val):
             fmt = '%Y-%m-%d %H:%M:%S'
@@ -40,13 +40,13 @@
                         # nullable due to FK problems
                         v = None
                     setattr(ul, k, v)
-                Session().add(ul)
-            Session().commit()
+                meta.Session().add(ul)
+            meta.Session().commit()
 
     @classmethod
     def teardown_class(cls):
         UserLog.query().delete()
-        Session().commit()
+        meta.Session().commit()
 
     def test_index(self):
         self.log_user()
--- a/kallithea/tests/functional/test_admin_gists.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_admin_gists.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,6 +1,6 @@
+from kallithea.model import meta
 from kallithea.model.db import Gist, User
 from kallithea.model.gist import GistModel
-from kallithea.model.meta import Session
 from kallithea.tests import base
 
 
@@ -14,7 +14,7 @@
     gist = GistModel().create(description, owner=owner, ip_addr=base.IP_ADDR,
                        gist_mapping=gist_mapping, gist_type=gist_type,
                        lifetime=lifetime)
-    Session().commit()
+    meta.Session().commit()
     return gist
 
 
@@ -23,7 +23,7 @@
     def teardown_method(self, method):
         for g in Gist.query():
             GistModel().delete(g)
-        Session().commit()
+        meta.Session().commit()
 
     def test_index(self):
         self.log_user()
@@ -90,7 +90,7 @@
         self.log_user()
         gist = _create_gist('never-see-me')
         gist.gist_expires = 0  # 1970
-        Session().commit()
+        meta.Session().commit()
 
         response = self.app.get(base.url('gist', gist_id=gist.gist_access_id), status=404)
 
--- a/kallithea/tests/functional/test_admin_repo_groups.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_admin_repo_groups.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,4 +1,4 @@
-from kallithea.model.meta import Session
+from kallithea.model import meta
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.tests.base import TestController, url
 from kallithea.tests.fixture import Fixture
@@ -23,4 +23,4 @@
         response.mustcontain('already exists')
 
         RepoGroupModel().delete(group_name)
-        Session().commit()
+        meta.Session().commit()
--- a/kallithea/tests/functional/test_admin_repos.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_admin_repos.py	Mon Oct 12 11:21:15 2020 +0200
@@ -8,8 +8,8 @@
 
 import kallithea
 from kallithea.lib import vcs
+from kallithea.model import meta
 from kallithea.model.db import Permission, Repository, Ui, User, UserRepoToPerm
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.model.user import UserModel
@@ -61,7 +61,7 @@
                                % (repo_name, repo_name))
 
         # test if the repo was created in the database
-        new_repo = Session().query(Repository) \
+        new_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == repo_name).one()
 
         assert new_repo.repo_name == repo_name
@@ -79,7 +79,7 @@
             pytest.fail('no repo %s in filesystem' % repo_name)
 
         RepoModel().delete(repo_name)
-        Session().commit()
+        meta.Session().commit()
 
     def test_case_insensitivity(self):
         self.log_user()
@@ -102,7 +102,7 @@
         response.mustcontain('already exists')
 
         RepoModel().delete(repo_name)
-        Session().commit()
+        meta.Session().commit()
 
     def test_create_in_group(self):
         self.log_user()
@@ -112,7 +112,7 @@
         gr = RepoGroupModel().create(group_name=group_name,
                                      group_description='test',
                                      owner=base.TEST_USER_ADMIN_LOGIN)
-        Session().commit()
+        meta.Session().commit()
 
         repo_name = 'ingroup'
         repo_name_full = kallithea.URL_SEP.join([group_name, repo_name])
@@ -131,7 +131,7 @@
                                'Created repository <a href="/%s">%s</a>'
                                % (repo_name_full, repo_name_full))
         # test if the repo was created in the database
-        new_repo = Session().query(Repository) \
+        new_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == repo_name_full).one()
         new_repo_id = new_repo.repo_id
 
@@ -152,12 +152,12 @@
             vcs.get_repo(os.path.join(Ui.get_by_key('paths', '/').ui_value, repo_name_full))
         except vcs.exceptions.VCSError:
             RepoGroupModel().delete(group_name)
-            Session().commit()
+            meta.Session().commit()
             pytest.fail('no repo %s in filesystem' % repo_name)
 
         RepoModel().delete(repo_name_full)
         RepoGroupModel().delete(group_name)
-        Session().commit()
+        meta.Session().commit()
 
     def test_create_in_group_without_needed_permissions(self):
         usr = self.log_user(base.TEST_USER_REGULAR_LOGIN, base.TEST_USER_REGULAR_PASS)
@@ -176,20 +176,20 @@
         user_model.grant_perm(base.TEST_USER_REGULAR_LOGIN, 'hg.create.none')
         user_model.revoke_perm(base.TEST_USER_REGULAR_LOGIN, 'hg.fork.repository')
         user_model.grant_perm(base.TEST_USER_REGULAR_LOGIN, 'hg.fork.none')
-        Session().commit()
+        meta.Session().commit()
 
         ## create GROUP
         group_name = 'reg_sometest_%s' % self.REPO_TYPE
         gr = RepoGroupModel().create(group_name=group_name,
                                      group_description='test',
                                      owner=base.TEST_USER_ADMIN_LOGIN)
-        Session().commit()
+        meta.Session().commit()
 
         group_name_allowed = 'reg_sometest_allowed_%s' % self.REPO_TYPE
         gr_allowed = RepoGroupModel().create(group_name=group_name_allowed,
                                      group_description='test',
                                      owner=base.TEST_USER_REGULAR_LOGIN)
-        Session().commit()
+        meta.Session().commit()
 
         repo_name = 'ingroup'
         repo_name_full = kallithea.URL_SEP.join([group_name, repo_name])
@@ -223,7 +223,7 @@
                                'Created repository <a href="/%s">%s</a>'
                                % (repo_name_full, repo_name_full))
         # test if the repo was created in the database
-        new_repo = Session().query(Repository) \
+        new_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == repo_name_full).one()
         new_repo_id = new_repo.repo_id
 
@@ -244,13 +244,13 @@
             vcs.get_repo(os.path.join(Ui.get_by_key('paths', '/').ui_value, repo_name_full))
         except vcs.exceptions.VCSError:
             RepoGroupModel().delete(group_name)
-            Session().commit()
+            meta.Session().commit()
             pytest.fail('no repo %s in filesystem' % repo_name)
 
         RepoModel().delete(repo_name_full)
         RepoGroupModel().delete(group_name)
         RepoGroupModel().delete(group_name_allowed)
-        Session().commit()
+        meta.Session().commit()
 
     def test_create_in_group_inherit_permissions(self):
         self.log_user()
@@ -264,7 +264,7 @@
         RepoGroupModel().grant_user_permission(gr, base.TEST_USER_REGULAR_LOGIN, perm)
 
         ## add repo permissions
-        Session().commit()
+        meta.Session().commit()
 
         repo_name = 'ingroup_inherited_%s' % self.REPO_TYPE
         repo_name_full = kallithea.URL_SEP.join([group_name, repo_name])
@@ -284,7 +284,7 @@
                                'Created repository <a href="/%s">%s</a>'
                                % (repo_name_full, repo_name_full))
         # test if the repo was created in the database
-        new_repo = Session().query(Repository) \
+        new_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == repo_name_full).one()
         new_repo_id = new_repo.repo_id
 
@@ -301,7 +301,7 @@
             vcs.get_repo(os.path.join(Ui.get_by_key('paths', '/').ui_value, repo_name_full))
         except vcs.exceptions.VCSError:
             RepoGroupModel().delete(group_name)
-            Session().commit()
+            meta.Session().commit()
             pytest.fail('no repo %s in filesystem' % repo_name)
 
         # check if inherited permissiona are applied
@@ -316,7 +316,7 @@
 
         RepoModel().delete(repo_name_full)
         RepoGroupModel().delete(group_name)
-        Session().commit()
+        meta.Session().commit()
 
     def test_create_remote_repo_wrong_clone_uri(self):
         self.log_user()
@@ -373,7 +373,7 @@
                                'Created repository <a href="/%s">%s</a>'
                                % (repo_name, repo_name))
         # test if the repo was created in the database
-        new_repo = Session().query(Repository) \
+        new_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == repo_name).one()
 
         assert new_repo.repo_name == repo_name
@@ -398,7 +398,7 @@
         response.follow()
 
         # check if repo was deleted from db
-        deleted_repo = Session().query(Repository) \
+        deleted_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == repo_name).scalar()
 
         assert deleted_repo is None
@@ -423,7 +423,7 @@
                                'Created repository <a href="/%s">%s</a>'
                                % (urllib.parse.quote(repo_name), repo_name))
         # test if the repo was created in the database
-        new_repo = Session().query(Repository) \
+        new_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == repo_name).one()
 
         assert new_repo.repo_name == repo_name
@@ -446,7 +446,7 @@
         response.follow()
 
         # check if repo was deleted from db
-        deleted_repo = Session().query(Repository) \
+        deleted_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == repo_name).scalar()
 
         assert deleted_repo is None
@@ -508,7 +508,7 @@
 
         # update this permission back
         perm[0].permission = Permission.get_by_key('repository.read')
-        Session().commit()
+        meta.Session().commit()
 
     def test_set_repo_fork_has_no_self_id(self):
         self.log_user()
@@ -586,7 +586,7 @@
         user_model.grant_perm(base.TEST_USER_REGULAR_LOGIN, 'hg.create.none')
         user_model.revoke_perm(base.TEST_USER_REGULAR_LOGIN, 'hg.fork.repository')
         user_model.grant_perm(base.TEST_USER_REGULAR_LOGIN, 'hg.fork.none')
-        Session().commit()
+        meta.Session().commit()
 
 
         user = User.get(usr['user_id'])
@@ -603,7 +603,7 @@
         response.mustcontain('<span class="error-message">Invalid value</span>')
 
         RepoModel().delete(repo_name)
-        Session().commit()
+        meta.Session().commit()
 
     @mock.patch.object(RepoModel, '_create_filesystem_repo', raise_exception)
     def test_create_repo_when_filesystem_op_fails(self):
--- a/kallithea/tests/functional/test_admin_user_groups.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_admin_user_groups.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
+from kallithea.model import meta
 from kallithea.model.db import Permission, UserGroup, UserGroupToPerm
-from kallithea.model.meta import Session
 from kallithea.tests import base
 
 
@@ -52,13 +52,13 @@
         self.checkSessionFlash(response,
                                'Created user group ')
 
-        gr = Session().query(UserGroup) \
+        gr = meta.Session().query(UserGroup) \
             .filter(UserGroup.users_group_name == users_group_name).one()
 
         response = self.app.post(base.url('delete_users_group', id=gr.users_group_id),
             params={'_session_csrf_secret_token': self.session_csrf_secret_token()})
 
-        gr = Session().query(UserGroup) \
+        gr = meta.Session().query(UserGroup) \
             .filter(UserGroup.users_group_name == users_group_name).scalar()
 
         assert gr is None
@@ -121,7 +121,7 @@
         response = self.app.post(base.url('delete_users_group', id=ug.users_group_id),
             params={'_session_csrf_secret_token': self.session_csrf_secret_token()})
         response = response.follow()
-        gr = Session().query(UserGroup) \
+        gr = meta.Session().query(UserGroup) \
             .filter(UserGroup.users_group_name == users_group_name).scalar()
 
         assert gr is None
@@ -188,7 +188,7 @@
         response = self.app.post(base.url('delete_users_group', id=ug.users_group_id),
             params={'_session_csrf_secret_token': self.session_csrf_secret_token()})
         response = response.follow()
-        gr = Session().query(UserGroup) \
+        gr = meta.Session().query(UserGroup) \
                            .filter(UserGroup.users_group_name ==
                                    users_group_name).scalar()
 
--- a/kallithea/tests/functional/test_admin_users.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_admin_users.py	Mon Oct 12 11:21:15 2020 +0200
@@ -21,9 +21,8 @@
 from kallithea.controllers.admin.users import UsersController
 from kallithea.lib import helpers as h
 from kallithea.lib.auth import check_password
-from kallithea.model import validators
+from kallithea.model import meta, validators
 from kallithea.model.db import Permission, RepoGroup, User, UserApiKeys, UserSshKeys
-from kallithea.model.meta import Session
 from kallithea.model.user import UserModel
 from kallithea.tests import base
 from kallithea.tests.fixture import Fixture
@@ -51,7 +50,7 @@
     def teardown_class(cls):
         if User.get_by_username(cls.test_user_1):
             UserModel().delete(cls.test_user_1)
-            Session().commit()
+            meta.Session().commit()
 
     def test_index(self):
         self.log_user()
@@ -86,7 +85,7 @@
         response = response.follow()
         response.mustcontain("""%s user settings""" % username) # in <title>
 
-        new_user = Session().query(User). \
+        new_user = meta.Session().query(User). \
             filter(User.username == username).one()
 
         assert new_user.username == username
@@ -120,7 +119,7 @@
         response.mustcontain("""<span class="error-message">An email address must contain a single @</span>""")
 
         def get_user():
-            Session().query(User).filter(User.username == username).one()
+            meta.Session().query(User).filter(User.username == username).one()
 
         with pytest.raises(NoResultFound):
             get_user(), 'found user in database'
@@ -151,7 +150,7 @@
                                   extern_type='internal',
                                   extern_name=self.test_user_1,
                                   skip_if_exists=True)
-        Session().commit()
+        meta.Session().commit()
         params = usr.get_api_data(True)
         params.update({'password_confirmation': ''})
         params.update({'new_password': ''})
@@ -185,7 +184,7 @@
 
         fixture.create_user(name=username)
 
-        new_user = Session().query(User) \
+        new_user = meta.Session().query(User) \
             .filter(User.username == username).one()
         response = self.app.post(base.url('delete_user', id=new_user.user_id),
             params={'_session_csrf_secret_token': self.session_csrf_secret_token()})
@@ -200,7 +199,7 @@
         fixture.create_user(name=username)
         fixture.create_repo(name=reponame, cur_user=username)
 
-        new_user = Session().query(User) \
+        new_user = meta.Session().query(User) \
             .filter(User.username == username).one()
         response = self.app.post(base.url('delete_user', id=new_user.user_id),
             params={'_session_csrf_secret_token': self.session_csrf_secret_token()})
@@ -251,7 +250,7 @@
         fixture.create_user(name=username)
         ug = fixture.create_user_group(name=groupname, cur_user=username)
 
-        new_user = Session().query(User) \
+        new_user = meta.Session().query(User) \
             .filter(User.username == username).one()
         response = self.app.post(base.url('delete_user', id=new_user.user_id),
             params={'_session_csrf_secret_token': self.session_csrf_secret_token()})
@@ -283,7 +282,7 @@
         user = UserModel().create_or_update(username='dummy', password='qwe',
                                             email='dummy', firstname='a',
                                             lastname='b')
-        Session().commit()
+        meta.Session().commit()
         uid = user.user_id
 
         try:
@@ -303,7 +302,7 @@
             assert UserModel().has_perm(uid, perm_create) == True
         finally:
             UserModel().delete(uid)
-            Session().commit()
+            meta.Session().commit()
 
     def test_revoke_perm_create_repo(self):
         self.log_user()
@@ -313,7 +312,7 @@
         user = UserModel().create_or_update(username='dummy', password='qwe',
                                             email='dummy', firstname='a',
                                             lastname='b')
-        Session().commit()
+        meta.Session().commit()
         uid = user.user_id
 
         try:
@@ -332,7 +331,7 @@
             assert UserModel().has_perm(uid, perm_create) == False
         finally:
             UserModel().delete(uid)
-            Session().commit()
+            meta.Session().commit()
 
     def test_add_perm_fork_repo(self):
         self.log_user()
@@ -342,7 +341,7 @@
         user = UserModel().create_or_update(username='dummy', password='qwe',
                                             email='dummy', firstname='a',
                                             lastname='b')
-        Session().commit()
+        meta.Session().commit()
         uid = user.user_id
 
         try:
@@ -362,7 +361,7 @@
             assert UserModel().has_perm(uid, perm_create) == True
         finally:
             UserModel().delete(uid)
-            Session().commit()
+            meta.Session().commit()
 
     def test_revoke_perm_fork_repo(self):
         self.log_user()
@@ -372,7 +371,7 @@
         user = UserModel().create_or_update(username='dummy', password='qwe',
                                             email='dummy', firstname='a',
                                             lastname='b')
-        Session().commit()
+        meta.Session().commit()
         uid = user.user_id
 
         try:
@@ -391,7 +390,7 @@
             assert UserModel().has_perm(uid, perm_create) == False
         finally:
             UserModel().delete(uid)
-            Session().commit()
+            meta.Session().commit()
 
     def test_ips(self):
         self.log_user()
@@ -434,7 +433,7 @@
         ip_range = '127.0.0.1 - 127.0.0.1'
         with test_context(self.app):
             new_ip = UserModel().add_extra_ip(user_id, ip)
-            Session().commit()
+            meta.Session().commit()
         new_ip_id = new_ip.ip_id
 
         response = self.app.get(base.url('edit_user_ips', id=user_id))
@@ -477,8 +476,8 @@
                 response.mustcontain(api_key)
         finally:
             for api_key in UserApiKeys.query().filter(UserApiKeys.user_id == user_id).all():
-                Session().delete(api_key)
-                Session().commit()
+                meta.Session().delete(api_key)
+                meta.Session().commit()
 
     def test_remove_api_key(self):
         self.log_user()
@@ -535,8 +534,8 @@
         ssh_key = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).one()
         assert ssh_key.fingerprint == fingerprint
         assert ssh_key.description == description
-        Session().delete(ssh_key)
-        Session().commit()
+        meta.Session().delete(ssh_key)
+        meta.Session().commit()
 
     def test_remove_ssh_key(self):
         description = ''
--- a/kallithea/tests/functional/test_changeset_pullrequests_comments.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_changeset_pullrequests_comments.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,8 +1,8 @@
 import re
 
+from kallithea.model import meta
 from kallithea.model.changeset_status import ChangesetStatusModel
 from kallithea.model.db import ChangesetComment, PullRequest
-from kallithea.model.meta import Session
 from kallithea.tests import base
 
 
@@ -10,8 +10,8 @@
 
     def setup_method(self, method):
         for x in ChangesetComment.query().all():
-            Session().delete(x)
-        Session().commit()
+            meta.Session().delete(x)
+        meta.Session().commit()
 
     def test_create(self):
         self.log_user()
@@ -153,8 +153,8 @@
 
     def setup_method(self, method):
         for x in ChangesetComment.query().all():
-            Session().delete(x)
-        Session().commit()
+            meta.Session().delete(x)
+        meta.Session().commit()
 
     def _create_pr(self):
         response = self.app.post(base.url(controller='pullrequests', action='create',
--- a/kallithea/tests/functional/test_compare.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_compare.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from kallithea.model.meta import Session
+from kallithea.model import meta
 from kallithea.model.repo import RepoModel
 from kallithea.tests import base
 from kallithea.tests.fixture import Fixture
@@ -23,8 +23,8 @@
             RepoModel().delete(self.r2_id)
         if self.r1_id:
             RepoModel().delete(self.r1_id)
-        Session().commit()
-        Session.remove()
+        meta.Session().commit()
+        meta.Session.remove()
 
     def test_compare_forks_on_branch_extra_commits_hg(self):
         self.log_user()
@@ -457,12 +457,12 @@
 
         cs0 = fixture.commit_change(repo=r1_name, filename='file1',
                 content='line1', message='commit1', vcs_type='hg', newfile=True)
-        Session().commit()
+        meta.Session().commit()
         assert repo1.scm_instance.revisions == [cs0.raw_id]
         # fork the repo1
         repo2 = fixture.create_fork(r1_name, 'one-fork',
                                     cur_user=base.TEST_USER_ADMIN_LOGIN)
-        Session().commit()
+        meta.Session().commit()
         assert repo2.scm_instance.revisions == [cs0.raw_id]
         self.r2_id = repo2.repo_id
         r2_name = repo2.repo_name
@@ -530,12 +530,12 @@
         cs0 = fixture.commit_change(repo=r1_name, filename='file1',
                 content='line1', message='commit1', vcs_type='git',
                 newfile=True)
-        Session().commit()
+        meta.Session().commit()
         assert repo1.scm_instance.revisions == [cs0.raw_id]
         # fork the repo1
         repo2 = fixture.create_fork(r1_name, 'one-git-fork',
                                     cur_user=base.TEST_USER_ADMIN_LOGIN)
-        Session().commit()
+        meta.Session().commit()
         assert repo2.scm_instance.revisions == [cs0.raw_id]
         self.r2_id = repo2.repo_id
         r2_name = repo2.repo_name
--- a/kallithea/tests/functional/test_files.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_files.py	Mon Oct 12 11:21:15 2020 +0200
@@ -3,8 +3,8 @@
 import mimetypes
 import posixpath
 
+from kallithea.model import meta
 from kallithea.model.db import Repository
-from kallithea.model.meta import Session
 from kallithea.tests import base
 from kallithea.tests.fixture import Fixture
 
@@ -24,7 +24,7 @@
 def _set_downloads(repo_name, set_to):
     repo = Repository.get_by_repo_name(repo_name)
     repo.enable_downloads = set_to
-    Session().commit()
+    meta.Session().commit()
 
 
 class TestFilesController(base.TestController):
--- a/kallithea/tests/functional/test_forks.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_forks.py	Mon Oct 12 11:21:15 2020 +0200
@@ -2,8 +2,8 @@
 
 import urllib.parse
 
+from kallithea.model import meta
 from kallithea.model.db import Repository, User
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 from kallithea.model.user import UserModel
 from kallithea.tests import base
@@ -27,11 +27,11 @@
         self.password = 'qweqwe'
         u1 = fixture.create_user(self.username, password=self.password, email='fork_king@example.com')
         self.u1_id = u1.user_id
-        Session().commit()
+        meta.Session().commit()
 
     def teardown_method(self, method):
         fixture.destroy_user(self.u1_id)
-        Session().commit()
+        meta.Session().commit()
 
     def test_index(self):
         self.log_user()
@@ -48,7 +48,7 @@
             usr = User.get_default_user()
             user_model.revoke_perm(usr, 'hg.fork.repository')
             user_model.grant_perm(usr, 'hg.fork.none')
-            Session().commit()
+            meta.Session().commit()
             # try create a fork
             repo_name = self.REPO
             self.app.post(base.url(controller='forks', action='fork_create',
@@ -57,7 +57,7 @@
             usr = User.get_default_user()
             user_model.revoke_perm(usr, 'hg.fork.none')
             user_model.grant_perm(usr, 'hg.fork.repository')
-            Session().commit()
+            meta.Session().commit()
 
     def test_index_with_fork(self):
         self.log_user()
@@ -122,7 +122,7 @@
                 % (repo_name, fork_name_full, fork_name_full))
 
         # test if the fork was created in the database
-        fork_repo = Session().query(Repository) \
+        fork_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == fork_name_full).one()
 
         assert fork_repo.repo_name == fork_name_full
@@ -216,7 +216,7 @@
                 % (repo_name, fork_name, fork_name))
 
         # test if the fork was created in the database
-        fork_repo = Session().query(Repository) \
+        fork_repo = meta.Session().query(Repository) \
             .filter(Repository.repo_name == fork_name).one()
 
         assert fork_repo.repo_name == fork_name
@@ -239,7 +239,7 @@
         RepoModel().grant_user_permission(repo=forks[0],
                                           user=usr,
                                           perm='repository.read')
-        Session().commit()
+        meta.Session().commit()
 
         response = self.app.get(base.url(controller='forks', action='forks',
                                     repo_name=repo_name))
@@ -253,7 +253,7 @@
                                               user=usr, perm='repository.none')
             RepoModel().grant_user_permission(repo=forks[0],
                                               user=default_user, perm='repository.none')
-            Session().commit()
+            meta.Session().commit()
 
             # fork shouldn't be visible
             response = self.app.get(base.url(controller='forks', action='forks',
--- a/kallithea/tests/functional/test_home.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_home.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 import json
 
-from kallithea.model.meta import Session
+from kallithea.model import meta
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.tests import base
@@ -62,7 +62,7 @@
         finally:
             RepoModel().delete('gr1/repo_in_group')
             RepoGroupModel().delete(repo_group='gr1', force_delete=True)
-            Session().commit()
+            meta.Session().commit()
 
     def test_users_and_groups_data(self):
         fixture.create_user('evil', firstname='D\'o\'ct"o"r', lastname='Évíl')
--- a/kallithea/tests/functional/test_login.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_login.py	Mon Oct 12 11:21:15 2020 +0200
@@ -10,10 +10,9 @@
 from kallithea.lib import helpers as h
 from kallithea.lib.auth import check_password
 from kallithea.lib.utils2 import generate_api_key
-from kallithea.model import validators
+from kallithea.model import meta, validators
 from kallithea.model.api_key import ApiKeyModel
 from kallithea.model.db import User
-from kallithea.model.meta import Session
 from kallithea.model.user import UserModel
 from kallithea.tests import base
 from kallithea.tests.fixture import Fixture
@@ -362,7 +361,7 @@
         assert response.status == '302 Found'
         self.checkSessionFlash(response, 'You have successfully registered with Kallithea')
 
-        ret = Session().query(User).filter(User.username == 'test_regular4').one()
+        ret = meta.Session().query(User).filter(User.username == 'test_regular4').one()
         assert ret.username == username
         assert check_password(password, ret.password) == True
         assert ret.email == email
@@ -403,8 +402,8 @@
         new.name = name
         new.lastname = lastname
         new.api_key = generate_api_key()
-        Session().add(new)
-        Session().commit()
+        meta.Session().add(new)
+        meta.Session().commit()
 
         token = UserModel().get_reset_password_token(
             User.get_by_username(username), timestamp, self.session_csrf_secret_token())
@@ -522,13 +521,13 @@
 
     def test_access_page_via_extra_api_key(self):
         new_api_key = ApiKeyModel().create(base.TEST_USER_ADMIN_LOGIN, 'test')
-        Session().commit()
+        meta.Session().commit()
         self._api_key_test(new_api_key.api_key, status=200)
 
     def test_access_page_via_expired_api_key(self):
         new_api_key = ApiKeyModel().create(base.TEST_USER_ADMIN_LOGIN, 'test')
-        Session().commit()
+        meta.Session().commit()
         # patch the API key and make it expired
         new_api_key.expires = 0
-        Session().commit()
+        meta.Session().commit()
         self._api_key_test(new_api_key.api_key, status=403)
--- a/kallithea/tests/functional/test_my_account.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_my_account.py	Mon Oct 12 11:21:15 2020 +0200
@@ -3,8 +3,8 @@
 from tg.util.webtest import test_context
 
 from kallithea.lib import helpers as h
+from kallithea.model import meta
 from kallithea.model.db import Repository, User, UserApiKeys, UserFollowing, UserSshKeys
-from kallithea.model.meta import Session
 from kallithea.model.user import UserModel
 from kallithea.tests import base
 from kallithea.tests.fixture import Fixture
@@ -20,7 +20,7 @@
     def teardown_class(cls):
         if User.get_by_username(cls.test_user_1):
             UserModel().delete(cls.test_user_1)
-            Session().commit()
+            meta.Session().commit()
 
     def test_my_account(self):
         self.log_user()
@@ -216,8 +216,8 @@
                 response.mustcontain(api_key)
         finally:
             for api_key in UserApiKeys.query().all():
-                Session().delete(api_key)
-                Session().commit()
+                meta.Session().delete(api_key)
+                meta.Session().commit()
 
     def test_my_account_remove_api_key(self):
         usr = self.log_user(base.TEST_USER_REGULAR2_LOGIN, base.TEST_USER_REGULAR2_PASS)
@@ -269,8 +269,8 @@
         ssh_key = UserSshKeys.query().filter(UserSshKeys.user_id == user_id).one()
         assert ssh_key.fingerprint == fingerprint
         assert ssh_key.description == description
-        Session().delete(ssh_key)
-        Session().commit()
+        meta.Session().delete(ssh_key)
+        meta.Session().commit()
 
     def test_my_account_remove_ssh_key(self):
         description = ''
--- a/kallithea/tests/functional/test_pullrequests.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_pullrequests.py	Mon Oct 12 11:21:15 2020 +0200
@@ -3,8 +3,8 @@
 import pytest
 
 from kallithea.controllers.pullrequests import PullrequestsController
+from kallithea.model import meta
 from kallithea.model.db import PullRequest, User
-from kallithea.model.meta import Session
 from kallithea.tests import base
 from kallithea.tests.fixture import Fixture
 
@@ -256,7 +256,7 @@
         assert pr1.org_ref == 'branch:webvcs:9e6119747791ff886a5abe1193a730b6bf874e1c'
         assert pr1.other_ref == 'branch:default:948da46b29c125838a717f6a8496eb409717078d'
 
-        Session().rollback() # invalidate loaded PR objects before issuing next request.
+        meta.Session().rollback() # invalidate loaded PR objects before issuing next request.
 
         # create PR 2 (new iteration with same ancestor)
         response = self.app.post(
@@ -278,7 +278,7 @@
         assert pr2.org_ref == 'branch:webvcs:5ec21f21aafe95220f1fc4843a4a57c378498b71'
         assert pr2.other_ref == pr1.other_ref
 
-        Session().rollback() # invalidate loaded PR objects before issuing next request.
+        meta.Session().rollback() # invalidate loaded PR objects before issuing next request.
 
         # create PR 3 (new iteration with new ancestor)
         response = self.app.post(
@@ -308,13 +308,13 @@
         self.repo_name = 'main'
         repo = fixture.create_repo(self.repo_name, repo_type='hg')
         self.repo_scm_instance = repo.scm_instance
-        Session().commit()
+        meta.Session().commit()
         self.c = PullrequestsController()
 
     def teardown_method(self, method):
         fixture.destroy_repo('main')
-        Session().commit()
-        Session.remove()
+        meta.Session().commit()
+        meta.Session.remove()
 
     def test_repo_refs_empty_repo(self):
         # empty repo with no commits, no branches, no bookmarks, just one tag
--- a/kallithea/tests/functional/test_pullrequests_git.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_pullrequests_git.py	Mon Oct 12 11:21:15 2020 +0200
@@ -3,7 +3,7 @@
 import pytest
 
 from kallithea.controllers.pullrequests import PullrequestsController
-from kallithea.model.meta import Session
+from kallithea.model import meta
 from kallithea.tests import base
 from kallithea.tests.fixture import Fixture
 
@@ -92,13 +92,13 @@
         self.repo_name = 'main'
         repo = fixture.create_repo(self.repo_name, repo_type='git')
         self.repo_scm_instance = repo.scm_instance
-        Session().commit()
+        meta.Session().commit()
         self.c = PullrequestsController()
 
     def teardown_method(self, method):
         fixture.destroy_repo('main')
-        Session().commit()
-        Session.remove()
+        meta.Session().commit()
+        meta.Session.remove()
 
     def test_repo_refs_empty_repo(self):
         # empty repo with no commits, no branches, no bookmarks, just one tag
--- a/kallithea/tests/functional/test_search_indexing.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_search_indexing.py	Mon Oct 12 11:21:15 2020 +0200
@@ -2,7 +2,7 @@
 
 import kallithea
 from kallithea.lib.conf import INDEX_FILENAMES
-from kallithea.model.meta import Session
+from kallithea.model import meta
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.tests import base
@@ -103,8 +103,8 @@
                 RepoGroupModel().delete(groupids.pop(groupname),
                                         force_delete=True)
 
-        Session().commit()
-        Session.remove()
+        meta.Session().commit()
+        meta.Session.remove()
 
         rebuild_index(full_index=True) # rebuild fully for subsequent tests
 
--- a/kallithea/tests/functional/test_summary.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/functional/test_summary.py	Mon Oct 12 11:21:15 2020 +0200
@@ -14,8 +14,8 @@
 
 import pytest
 
+from kallithea.model import meta
 from kallithea.model.db import Repository
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 from kallithea.model.scm import ScmModel
 from kallithea.tests import base
@@ -120,7 +120,7 @@
             response.mustcontain("repo_1")
         finally:
             RepoModel().delete(Repository.get_by_repo_name('repo_1'))
-            Session().commit()
+            meta.Session().commit()
 
     def test_index_by_id_git(self):
         self.log_user()
@@ -141,7 +141,7 @@
     def _enable_stats(self, repo):
         r = Repository.get_by_repo_name(repo)
         r.enable_statistics = True
-        Session().commit()
+        meta.Session().commit()
 
     def test_index_trending(self):
         self.log_user()
--- a/kallithea/tests/models/common.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/common.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,6 +1,6 @@
 from kallithea.lib.auth import AuthUser
+from kallithea.model import meta
 from kallithea.model.db import RepoGroup, Repository, User
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.model.user import UserModel
@@ -11,7 +11,7 @@
 
 
 def _destroy_project_tree(test_u1_id):
-    Session.remove()
+    meta.Session.remove()
     repo_group = RepoGroup.get_by_group_name(group_name='g0')
     for el in reversed(repo_group.recursive_groups_and_repos()):
         if isinstance(el, Repository):
@@ -20,8 +20,8 @@
             RepoGroupModel().delete(el, force_delete=True)
 
     u = User.get(test_u1_id)
-    Session().delete(u)
-    Session().commit()
+    meta.Session().delete(u)
+    meta.Session().commit()
 
 
 def _create_project_tree():
--- a/kallithea/tests/models/test_notifications.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/test_notifications.py	Mon Oct 12 11:21:15 2020 +0200
@@ -7,8 +7,8 @@
 import kallithea.lib.celerylib
 import kallithea.lib.celerylib.tasks
 from kallithea.lib import helpers as h
+from kallithea.model import meta
 from kallithea.model.db import User
-from kallithea.model.meta import Session
 from kallithea.model.notification import EmailNotificationModel, NotificationModel
 from kallithea.model.user import UserModel
 from kallithea.tests import base
@@ -17,26 +17,26 @@
 class TestNotifications(base.TestController):
 
     def setup_method(self, method):
-        Session.remove()
+        meta.Session.remove()
         u1 = UserModel().create_or_update(username='u1',
                                         password='qweqwe',
                                         email='u1@example.com',
                                         firstname='u1', lastname='u1')
-        Session().commit()
+        meta.Session().commit()
         self.u1 = u1.user_id
 
         u2 = UserModel().create_or_update(username='u2',
                                         password='qweqwe',
                                         email='u2@example.com',
                                         firstname='u2', lastname='u3')
-        Session().commit()
+        meta.Session().commit()
         self.u2 = u2.user_id
 
         u3 = UserModel().create_or_update(username='u3',
                                         password='qweqwe',
                                         email='u3@example.com',
                                         firstname='u3', lastname='u3')
-        Session().commit()
+        meta.Session().commit()
         self.u3 = u3.user_id
 
     def test_create_notification(self):
--- a/kallithea/tests/models/test_permissions.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/test_permissions.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,7 +1,7 @@
 import kallithea
 from kallithea.lib.auth import AuthUser
+from kallithea.model import meta
 from kallithea.model.db import Permission, User, UserGroupRepoGroupToPerm, UserToPerm
-from kallithea.model.meta import Session
 from kallithea.model.permission import PermissionModel
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
@@ -21,7 +21,7 @@
         # recreate default user to get a clean start
         PermissionModel().create_default_permissions(user=User.DEFAULT_USER_NAME,
                                                      force=True)
-        Session().commit()
+        meta.Session().commit()
 
     def setup_method(self, method):
         self.u1 = UserModel().create_or_update(
@@ -41,7 +41,7 @@
             username='a1', password='qweqwe',
             email='a1@example.com', firstname='a1', lastname='a1', admin=True
         )
-        Session().commit()
+        meta.Session().commit()
 
     def teardown_method(self, method):
         if hasattr(self, 'test_repo'):
@@ -52,7 +52,7 @@
         UserModel().delete(self.u3)
         UserModel().delete(self.a1)
 
-        Session().commit() # commit early to avoid SQLAlchemy warning from double cascade delete to users_groups_members
+        meta.Session().commit() # commit early to avoid SQLAlchemy warning from double cascade delete to users_groups_members
 
         if hasattr(self, 'g1'):
             RepoGroupModel().delete(self.g1.group_id)
@@ -64,7 +64,7 @@
         if hasattr(self, 'ug1'):
             UserGroupModel().delete(self.ug1, force=True)
 
-        Session().commit()
+        meta.Session().commit()
 
     def test_default_perms_set(self):
         u1_auth = AuthUser(user_id=self.u1.user_id)
@@ -72,7 +72,7 @@
         new_perm = 'repository.write'
         RepoModel().grant_user_permission(repo=base.HG_REPO, user=self.u1,
                                           perm=new_perm)
-        Session().commit()
+        meta.Session().commit()
 
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.repository_permissions[base.HG_REPO] == new_perm
@@ -83,7 +83,7 @@
         new_perm = 'repository.write'
         RepoModel().grant_user_permission(repo=base.HG_REPO, user=self.a1,
                                           perm=new_perm)
-        Session().commit()
+        meta.Session().commit()
         # cannot really downgrade admins permissions !? they still gets set as
         # admin !
         u1_auth = AuthUser(user_id=self.a1.user_id)
@@ -113,7 +113,7 @@
 
         # set user permission none
         RepoModel().grant_user_permission(repo=base.HG_REPO, user=self.u1, perm='repository.none')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.repository_permissions[base.HG_REPO] == 'repository.read' # inherit from default user
 
@@ -150,7 +150,7 @@
         new_perm_h = 'repository.write'
         RepoModel().grant_user_permission(repo=base.HG_REPO, user=self.u1,
                                           perm=new_perm_h)
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.repository_permissions[base.HG_REPO] == new_perm_h
 
@@ -212,7 +212,7 @@
                                                perm='group.read')
         RepoGroupModel().grant_user_permission(repo_group=self.g2, user=self.u2,
                                                perm='group.read')
-        Session().commit()
+        meta.Session().commit()
         assert self.u1 != self.u2
         # u1 and anon should have not change perms while u2 should !
         u1_auth = AuthUser(user_id=self.u1.user_id)
@@ -242,7 +242,7 @@
         self.ug1 = fixture.create_user_group('G1')
         # add user to group
         UserGroupModel().add_user_to_group(self.ug1, self.u1)
-        Session().commit()
+        meta.Session().commit()
 
         # check if user is in the group
         members = [x.user_id for x in UserGroupModel().get(self.ug1.users_group_id).members]
@@ -260,9 +260,9 @@
         RepoGroupModel().grant_user_group_permission(repo_group=self.g1,
                                                       group_name=self.ug1,
                                                       perm='group.read')
-        Session().commit()
+        meta.Session().commit()
         # check if the
-        obj = Session().query(UserGroupRepoGroupToPerm) \
+        obj = meta.Session().query(UserGroupRepoGroupToPerm) \
             .filter(UserGroupRepoGroupToPerm.group == self.g1) \
             .filter(UserGroupRepoGroupToPerm.users_group == self.ug1) \
             .scalar()
@@ -283,7 +283,7 @@
         user_model.grant_perm(usr, 'hg.create.repository')
         user_model.revoke_perm(usr, 'hg.fork.none')
         user_model.grant_perm(usr, 'hg.fork.repository')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         # this user will have inherited permissions from default user
         assert u1_auth.global_permissions == set(['hg.create.repository', 'hg.fork.repository',
@@ -300,7 +300,7 @@
         user_model.grant_perm(usr, 'hg.create.none')
         user_model.revoke_perm(usr, 'hg.fork.repository')
         user_model.grant_perm(usr, 'hg.fork.none')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         # this user will have inherited permissions from default user
         assert u1_auth.global_permissions == set(['hg.create.none', 'hg.fork.none',
@@ -324,7 +324,7 @@
         user_model.revoke_perm(self.u1, 'hg.fork.repository')
         user_model.grant_perm(self.u1, 'hg.fork.none')
 
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         # this user will have inherited more permissions from default user
         assert u1_auth.global_permissions == set([
@@ -350,7 +350,7 @@
         user_model.revoke_perm(self.u1, 'hg.fork.none')
         user_model.grant_perm(self.u1, 'hg.fork.repository')
 
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         # this user will have inherited less permissions from default user
         assert u1_auth.global_permissions == set([
@@ -383,7 +383,7 @@
         user_model.revoke_perm(usr, 'hg.fork.repository')
         user_model.grant_perm(usr, 'hg.fork.none')
 
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
 
         assert u1_auth.global_permissions == set(['hg.create.none', 'hg.fork.none',
@@ -415,7 +415,7 @@
         user_model.revoke_perm(usr, 'hg.fork.none')
         user_model.grant_perm(usr, 'hg.fork.repository')
 
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
 
         assert u1_auth.global_permissions == set(['hg.create.repository', 'hg.fork.repository',
@@ -445,7 +445,7 @@
         RepoModel().grant_user_permission(self.test_repo,
                                           user='default',
                                           perm='repository.write')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.repository_permissions['myownrepo'] == 'repository.write'
 
@@ -469,7 +469,7 @@
         RepoModel().grant_user_permission(self.test_repo,
                                           user='default',
                                           perm='repository.admin')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.repository_permissions['myownrepo'] == 'repository.admin'
 
@@ -489,7 +489,7 @@
         RepoGroupModel().grant_user_permission(self.g1,
                                                user='default',
                                                perm='group.write')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.repository_group_permissions.get('group1') == 'group.write'
 
@@ -509,7 +509,7 @@
         RepoGroupModel().grant_user_permission(self.g1,
                                                user='default',
                                                perm='group.admin')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.repository_group_permissions.get('group1') == 'group.admin'
 
@@ -529,7 +529,7 @@
         UserGroupModel().grant_user_permission(self.ug2,
                                                user='default',
                                                perm='usergroup.write')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.user_group_permissions['G1'] == 'usergroup.read'
         assert u1_auth.user_group_permissions['G2'] == 'usergroup.write'
@@ -550,7 +550,7 @@
         UserGroupModel().grant_user_permission(self.ug2,
                                                user='default',
                                                perm='usergroup.admin')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.user_group_permissions['G1'] == 'usergroup.read'
         assert u1_auth.user_group_permissions['G2'] == 'usergroup.admin'
@@ -571,7 +571,7 @@
                                                  group_name=self.ug1,
                                                  perm='repository.none')
 
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.repository_permissions['myownrepo'] == 'repository.admin'
 
@@ -587,7 +587,7 @@
         # set his permission as user, he should still be admin
         RepoModel().grant_user_permission(self.test_repo, user=self.u1,
                                           perm='repository.none')
-        Session().commit()
+        meta.Session().commit()
         u1_auth = AuthUser(user_id=self.u1.user_id)
         assert u1_auth.repository_permissions['myownrepo'] == 'repository.admin'
 
@@ -608,8 +608,8 @@
         perms = UserToPerm.query() \
                 .filter(UserToPerm.user == self.u1) \
                 .all()
-        Session().delete(perms[0])
-        Session().commit()
+        meta.Session().delete(perms[0])
+        meta.Session().commit()
 
         self._test_def_perm_equal(user=self.u1, change_factor=-1)
 
@@ -640,7 +640,7 @@
                 .filter(UserToPerm.permission == old) \
                 .one()
         p.permission = new
-        Session().commit()
+        meta.Session().commit()
 
         PermissionModel().create_default_permissions(user=self.u1)
         self._test_def_perm_equal(user=self.u1)
--- a/kallithea/tests/models/test_repo_groups.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/test_repo_groups.py	Mon Oct 12 11:21:15 2020 +0200
@@ -4,8 +4,8 @@
 from sqlalchemy.exc import IntegrityError
 
 import kallithea
+from kallithea.model import meta
 from kallithea.model.db import RepoGroup
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.tests import base
@@ -43,7 +43,7 @@
         self.g3 = fixture.create_repo_group('test3', skip_if_exists=True)
 
     def teardown_method(self, method):
-        Session.remove()
+        meta.Session.remove()
 
     def __check_path(self, *path):
         """
@@ -58,7 +58,7 @@
 
     def test_create_group(self):
         g = fixture.create_repo_group('newGroup')
-        Session().commit()
+        meta.Session().commit()
         assert g.full_path == 'newGroup'
 
         assert self.__check_path('newGroup')
@@ -66,7 +66,7 @@
         # test_create_same_name_group
         with pytest.raises(IntegrityError):
             fixture.create_repo_group('newGroup')
-        Session().rollback()
+        meta.Session().rollback()
 
     def test_same_subgroup(self):
         sg1 = fixture.create_repo_group('sub1', parent_group_id=self.g1.group_id)
@@ -126,7 +126,7 @@
         assert r.repo_name == 'john'
         # put repo into group
         r = _update_repo('john', repo_group=g1.group_id)
-        Session().commit()
+        meta.Session().commit()
         assert r.repo_name == 'g1/john'
 
         _update_repo_group(g1.group_id, 'g1', parent_id=g2.group_id)
@@ -143,7 +143,7 @@
         assert self.__check_path('t11', 't22')
 
         g2 = _update_repo_group(g2.group_id, 'g22', parent_id=None)
-        Session().commit()
+        meta.Session().commit()
 
         assert g2.group_name == 'g22'
         # we moved out group from t1 to '' so it's full path should be 'g2'
@@ -160,7 +160,7 @@
 
         ## rename L1 all groups should be now changed
         _update_repo_group(g1.group_id, 'L1_NEW')
-        Session().commit()
+        meta.Session().commit()
         assert g1.full_path == 'L1_NEW'
         assert g2.full_path == 'L1_NEW/L2'
         assert g3.full_path == 'L1_NEW/L2/L3'
@@ -175,7 +175,7 @@
         r = fixture.create_repo('R1/R2/R3/R3_REPO', repo_group=g3.group_id)
         ## rename L1 all groups should be now changed
         _update_repo_group(g1.group_id, 'R1', parent_id=g4.group_id)
-        Session().commit()
+        meta.Session().commit()
         assert g1.full_path == 'R1_NEW/R1'
         assert g2.full_path == 'R1_NEW/R1/R2'
         assert g3.full_path == 'R1_NEW/R1/R2/R3'
@@ -191,7 +191,7 @@
 
         ## rename L1 all groups should be now changed
         _update_repo_group(g1.group_id, 'X1_PRIM', parent_id=g4.group_id)
-        Session().commit()
+        meta.Session().commit()
         assert g1.full_path == 'X1_NEW/X1_PRIM'
         assert g2.full_path == 'X1_NEW/X1_PRIM/X2'
         assert g3.full_path == 'X1_NEW/X1_PRIM/X2/X3'
--- a/kallithea/tests/models/test_repos.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/test_repos.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,8 +1,8 @@
 import pytest
 
 from kallithea.lib.exceptions import AttachedForksError
+from kallithea.model import meta
 from kallithea.model.db import Repository
-from kallithea.model.meta import Session
 from kallithea.model.repo import RepoModel
 from kallithea.tests import base
 from kallithea.tests.fixture import Fixture
@@ -14,44 +14,44 @@
 class TestRepos(base.TestController):
 
     def teardown_method(self, method):
-        Session.remove()
+        meta.Session.remove()
 
     def test_remove_repo(self):
         repo = fixture.create_repo(name='test-repo-1')
-        Session().commit()
+        meta.Session().commit()
 
         RepoModel().delete(repo=repo)
-        Session().commit()
+        meta.Session().commit()
 
         assert Repository.get_by_repo_name(repo_name='test-repo-1') is None
 
     def test_remove_repo_repo_raises_exc_when_attached_forks(self):
         repo = fixture.create_repo(name='test-repo-1')
-        Session().commit()
+        meta.Session().commit()
 
         fixture.create_fork(repo.repo_name, 'test-repo-fork-1')
-        Session().commit()
+        meta.Session().commit()
 
         with pytest.raises(AttachedForksError):
             RepoModel().delete(repo=repo)
         # cleanup
         RepoModel().delete(repo='test-repo-fork-1')
         RepoModel().delete(repo='test-repo-1')
-        Session().commit()
+        meta.Session().commit()
 
     def test_remove_repo_delete_forks(self):
         repo = fixture.create_repo(name='test-repo-1')
-        Session().commit()
+        meta.Session().commit()
 
         fork = fixture.create_fork(repo.repo_name, 'test-repo-fork-1')
-        Session().commit()
+        meta.Session().commit()
 
         # fork of fork
         fixture.create_fork(fork.repo_name, 'test-repo-fork-fork-1')
-        Session().commit()
+        meta.Session().commit()
 
         RepoModel().delete(repo=repo, forks='delete')
-        Session().commit()
+        meta.Session().commit()
 
         assert Repository.get_by_repo_name(repo_name='test-repo-1') is None
         assert Repository.get_by_repo_name(repo_name='test-repo-fork-1') is None
@@ -59,17 +59,17 @@
 
     def test_remove_repo_detach_forks(self):
         repo = fixture.create_repo(name='test-repo-1')
-        Session().commit()
+        meta.Session().commit()
 
         fork = fixture.create_fork(repo.repo_name, 'test-repo-fork-1')
-        Session().commit()
+        meta.Session().commit()
 
         # fork of fork
         fixture.create_fork(fork.repo_name, 'test-repo-fork-fork-1')
-        Session().commit()
+        meta.Session().commit()
 
         RepoModel().delete(repo=repo, forks='detach')
-        Session().commit()
+        meta.Session().commit()
 
         try:
             assert Repository.get_by_repo_name(repo_name='test-repo-1') is None
@@ -78,4 +78,4 @@
         finally:
             RepoModel().delete(repo='test-repo-fork-fork-1')
             RepoModel().delete(repo='test-repo-fork-1')
-            Session().commit()
+            meta.Session().commit()
--- a/kallithea/tests/models/test_settings.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/test_settings.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,5 +1,5 @@
+from kallithea.model import meta
 from kallithea.model.db import Setting
-from kallithea.model.meta import Session
 
 
 name = 'spam-setting-name'
@@ -8,7 +8,7 @@
 def test_passing_list_setting_value_results_in_string_valued_setting():
     assert Setting.get_by_name(name) is None
     setting = Setting.create_or_update(name, ['spam', 'eggs'])
-    Session().flush() # must flush so we can delete it below
+    meta.Session().flush() # must flush so we can delete it below
     try:
         assert Setting.get_by_name(name) is not None
         # Quirk: list value is stringified.
@@ -16,24 +16,24 @@
                == "['spam', 'eggs']"
         assert Setting.get_by_name(name).app_settings_type == 'unicode'
     finally:
-        Session().delete(setting)
+        meta.Session().delete(setting)
 
 
 def test_list_valued_setting_creation_requires_manual_value_formatting():
     assert Setting.get_by_name(name) is None
     # Quirk: need manual formatting of list setting value.
     setting = Setting.create_or_update(name, 'spam,eggs', type='list')
-    Session().flush() # must flush so we can delete it below
+    meta.Session().flush() # must flush so we can delete it below
     try:
         assert setting.app_settings_value == ['spam', 'eggs']
     finally:
-        Session().delete(setting)
+        meta.Session().delete(setting)
 
 
 def test_list_valued_setting_update():
     assert Setting.get_by_name(name) is None
     setting = Setting.create_or_update(name, 'spam', type='list')
-    Session().flush() # must flush so we can delete it below
+    meta.Session().flush() # must flush so we can delete it below
     try:
         assert setting.app_settings_value == ['spam']
         # Assign back setting value.
@@ -43,4 +43,4 @@
         setting.app_settings_value = setting.app_settings_value
         assert setting.app_settings_value == ["[\"['spam']\"]"]
     finally:
-        Session().delete(setting)
+        meta.Session().delete(setting)
--- a/kallithea/tests/models/test_user_group_permissions_on_repo_groups.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/test_user_group_permissions_on_repo_groups.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,7 +1,7 @@
 import functools
 
+from kallithea.model import meta
 from kallithea.model.db import RepoGroup
-from kallithea.model.meta import Session
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.model.user_group import UserGroupModel
 from kallithea.tests.fixture import Fixture
@@ -34,20 +34,20 @@
     RepoGroupModel()._update_permissions(repo_group,
                                          perms_updates=perms_updates,
                                          recursive=recursive, check_perms=False)
-    Session().commit()
+    meta.Session().commit()
 
 
 def setup_module():
     global test_u2_id, test_u2_gr_id, _get_repo_perms, _get_group_perms
     test_u2 = _create_project_tree()
-    Session().commit()
+    meta.Session().commit()
     test_u2_id = test_u2.user_id
 
     gr1 = fixture.create_user_group('perms_group_1')
-    Session().commit()
+    meta.Session().commit()
     test_u2_gr_id = gr1.users_group_id
     UserGroupModel().add_user_to_group(gr1, user=test_u2_id)
-    Session().commit()
+    meta.Session().commit()
 
     _get_repo_perms = functools.partial(_get_perms, key='repositories',
                                         test_u1_id=test_u2_id)
--- a/kallithea/tests/models/test_user_groups.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/test_user_groups.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,5 +1,5 @@
+from kallithea.model import meta
 from kallithea.model.db import User, UserGroup
-from kallithea.model.meta import Session
 from kallithea.model.user_group import UserGroupModel
 from kallithea.tests import base
 from kallithea.tests.fixture import Fixture
@@ -14,7 +14,7 @@
         # delete all groups
         for gr in UserGroup.query():
             fixture.destroy_user_group(gr)
-        Session().commit()
+        meta.Session().commit()
 
     @base.parametrize('pre_existing,regular_should_be,external_should_be,groups,expected', [
         ([], [], [], [], []),
@@ -30,29 +30,29 @@
         # delete all groups
         for gr in UserGroup.query():
             fixture.destroy_user_group(gr)
-        Session().commit()
+        meta.Session().commit()
 
         user = User.get_by_username(base.TEST_USER_REGULAR_LOGIN)
         for gr in pre_existing:
             gr = fixture.create_user_group(gr)
-        Session().commit()
+        meta.Session().commit()
 
         # make sure use is just in those groups
         for gr in regular_should_be:
             gr = fixture.create_user_group(gr)
-            Session().commit()
+            meta.Session().commit()
             UserGroupModel().add_user_to_group(gr, user)
-            Session().commit()
+            meta.Session().commit()
 
         # now special external groups created by auth plugins
         for gr in external_should_be:
             gr = fixture.create_user_group(gr, user_group_data={'extern_type': 'container'})
-            Session().commit()
+            meta.Session().commit()
             UserGroupModel().add_user_to_group(gr, user)
-            Session().commit()
+            meta.Session().commit()
 
         UserGroupModel().enforce_groups(user, groups, 'container')
-        Session().commit()
+        meta.Session().commit()
 
         user = User.get_by_username(base.TEST_USER_REGULAR_LOGIN)
         in_groups = user.group_member
--- a/kallithea/tests/models/test_user_permissions_on_repo_groups.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/test_user_permissions_on_repo_groups.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,8 +1,8 @@
 import functools
 
 import kallithea
+from kallithea.model import meta
 from kallithea.model.db import RepoGroup, Repository
-from kallithea.model.meta import Session
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.tests.models.common import _check_expected_count, _create_project_tree, _destroy_project_tree, _get_perms, check_tree_perms, expected_count
 
@@ -36,13 +36,13 @@
     RepoGroupModel()._update_permissions(repo_group,
                                          perms_updates=perms_updates,
                                          recursive=recursive, check_perms=False)
-    Session().commit()
+    meta.Session().commit()
 
 
 def setup_module():
     global test_u1_id, _get_repo_perms, _get_group_perms
     test_u1 = _create_project_tree()
-    Session().commit()
+    meta.Session().commit()
     test_u1_id = test_u1.user_id
     _get_repo_perms = functools.partial(_get_perms, key='repositories',
                                         test_u1_id=test_u1_id)
--- a/kallithea/tests/models/test_users.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/models/test_users.py	Mon Oct 12 11:21:15 2020 +0200
@@ -1,7 +1,7 @@
 import pytest
 
+from kallithea.model import meta
 from kallithea.model.db import Permission, User, UserEmailMap, UserGroup, UserGroupMember
-from kallithea.model.meta import Session
 from kallithea.model.user import UserModel
 from kallithea.model.user_group import UserGroupModel
 from kallithea.tests import base
@@ -15,17 +15,17 @@
 
     @classmethod
     def setup_class(cls):
-        Session.remove()
+        meta.Session.remove()
 
     def teardown_method(self, method):
-        Session.remove()
+        meta.Session.remove()
 
     def test_create_and_remove(self):
         usr = UserModel().create_or_update(username='test_user',
                                            password='qweqwe',
                                            email='u232@example.com',
                                            firstname='u1', lastname='u1')
-        Session().commit()
+        meta.Session().commit()
         assert User.get_by_username('test_user') == usr
         assert User.get_by_username('test_USER', case_insensitive=True) == usr
         # User.get_by_username without explicit request for case insensitivty
@@ -36,15 +36,15 @@
 
         # make user group
         user_group = fixture.create_user_group('some_example_group')
-        Session().commit()
+        meta.Session().commit()
 
         UserGroupModel().add_user_to_group(user_group, usr)
-        Session().commit()
+        meta.Session().commit()
 
         assert UserGroup.get(user_group.users_group_id) == user_group
         assert UserGroupMember.query().count() == 1
         UserModel().delete(usr.user_id)
-        Session().commit()
+        meta.Session().commit()
 
         assert UserGroupMember.query().all() == []
 
@@ -53,30 +53,30 @@
                                            password='qweqwe',
                                      email='main_email@example.com',
                                      firstname='u1', lastname='u1')
-        Session().commit()
+        meta.Session().commit()
 
         with pytest.raises(AttributeError):
             m = UserEmailMap()
             m.email = 'main_email@example.com'
             m.user = usr
-            Session().add(m)
-            Session().commit()
+            meta.Session().add(m)
+            meta.Session().commit()
 
         UserModel().delete(usr.user_id)
-        Session().commit()
+        meta.Session().commit()
 
     def test_extra_email_map(self):
         usr = UserModel().create_or_update(username='test_user',
                                            password='qweqwe',
                                      email='main_email@example.com',
                                      firstname='u1', lastname='u1')
-        Session().commit()
+        meta.Session().commit()
 
         m = UserEmailMap()
         m.email = 'main_email2@example.com'
         m.user = usr
-        Session().add(m)
-        Session().commit()
+        meta.Session().add(m)
+        meta.Session().commit()
 
         u = User.get_by_email(email='MAIN_email@example.com')
         assert usr.user_id == u.user_id
@@ -98,7 +98,7 @@
         assert u is None
 
         UserModel().delete(usr.user_id)
-        Session().commit()
+        meta.Session().commit()
 
 
 class TestUsers(base.TestController):
@@ -115,13 +115,13 @@
             UserModel().revoke_perm(self.u1, p)
 
         UserModel().delete(self.u1)
-        Session().commit()
-        Session.remove()
+        meta.Session().commit()
+        meta.Session.remove()
 
     def test_add_perm(self):
         perm = Permission.query().all()[0]
         UserModel().grant_perm(self.u1, perm)
-        Session().commit()
+        meta.Session().commit()
         assert UserModel().has_perm(self.u1, perm) == True
 
     def test_has_perm(self):
@@ -133,10 +133,10 @@
     def test_revoke_perm(self):
         perm = Permission.query().all()[0]
         UserModel().grant_perm(self.u1, perm)
-        Session().commit()
+        meta.Session().commit()
         assert UserModel().has_perm(self.u1, perm) == True
 
         # revoke
         UserModel().revoke_perm(self.u1, perm)
-        Session().commit()
+        meta.Session().commit()
         assert UserModel().has_perm(self.u1, perm) == False
--- a/kallithea/tests/other/test_validators.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/other/test_validators.py	Mon Oct 12 11:21:15 2020 +0200
@@ -2,8 +2,8 @@
 import formencode
 import pytest
 
+from kallithea.model import meta
 from kallithea.model import validators as v
-from kallithea.model.meta import Session
 from kallithea.model.repo_group import RepoGroupModel
 from kallithea.model.user_group import UserGroupModel
 from kallithea.tests import base
@@ -17,7 +17,7 @@
 class TestRepoGroups(base.TestController):
 
     def teardown_method(self, method):
-        Session.remove()
+        meta.Session.remove()
 
     def test_Message_extractor(self):
         validator = v.ValidUsername()
@@ -60,7 +60,7 @@
 
         gr = fixture.create_user_group('test')
         gr2 = fixture.create_user_group('tes2')
-        Session().commit()
+        meta.Session().commit()
         with pytest.raises(formencode.Invalid):
             validator.to_python('test')
         assert gr.users_group_id is not None
@@ -76,7 +76,7 @@
             validator.to_python('TEST')
         UserGroupModel().delete(gr)
         UserGroupModel().delete(gr2)
-        Session().commit()
+        meta.Session().commit()
 
     def test_ValidRepoGroup(self):
         validator = v.ValidRepoGroup()
--- a/kallithea/tests/other/test_vcs_operations.py	Mon Oct 12 01:44:10 2020 +0200
+++ b/kallithea/tests/other/test_vcs_operations.py	Mon Oct 12 11:21:15 2020 +0200
@@ -38,8 +38,8 @@
 
 import kallithea
 from kallithea.lib.utils2 import ascii_bytes, safe_str
+from kallithea.model import meta
 from kallithea.model.db import Repository, Ui, User, UserIpMap, UserLog
-from kallithea.model.meta import Session
 from kallithea.model.ssh_key import SshKeyModel
 from kallithea.model.user import UserModel
 from kallithea.tests import base
@@ -75,7 +75,7 @@
         else:
             sshkeymodel = SshKeyModel()
             ssh_key = sshkeymodel.create(user, 'test key', cls.public_keys[user.username])
-            Session().commit()
+            meta.Session().commit()
 
         return cls._ssh_param(repo_name, user, ssh_key, client_ip)
 
@@ -223,7 +223,7 @@
 def set_anonymous_access(enable=True):
     user = User.get_default_user()
     user.active = enable
-    Session().commit()
+    meta.Session().commit()
     if enable != User.get_default_user().active:
         raise Exception('Cannot set anonymous access')
 
@@ -255,8 +255,8 @@
         for hook in ['prechangegroup', 'pretxnchangegroup', 'preoutgoing', 'changegroup', 'outgoing', 'incoming']:
             entry = Ui.get_by_key('hooks', '%s.testhook' % hook)
             if entry:
-                Session().delete(entry)
-        Session().commit()
+                meta.Session().delete(entry)
+        meta.Session().commit()
 
     @pytest.fixture(scope="module")
     def testfork(self):
@@ -314,7 +314,7 @@
     def test_push_new_repo(self, webserver, vt):
         # Clear the log so we know what is added
         UserLog.query().delete()
-        Session().commit()
+        meta.Session().commit()
 
         # Create an empty server repo using the API
         repo_name = 'new_%s_%s' % (vt.repo_type, next(_RandomNameSequence()))
@@ -358,7 +358,7 @@
         # <UserLog('id:new_git_XXX:user_created_repo')>
         # <UserLog('id:new_git_XXX:pull')>
         # <UserLog('id:new_git_XXX:push:aed9d4c1732a1927da3be42c47eb9afdc200d427,d38b083a07af10a9f44193486959a96a23db78da,4841ff9a2b385bec995f4679ef649adb3f437622')>
-        Session.close()  # make sure SA fetches all new log entries (apparently only needed for MariaDB/MySQL ...)
+        meta.Session.close()  # make sure SA fetches all new log entries (apparently only needed for MariaDB/MySQL ...)
         action_parts = [ul.action.split(':', 1) for ul in UserLog.query().order_by(UserLog.user_log_id)]
         assert [(t[0], (t[1].count(',') + 1) if len(t) == 2 else 0) for t in action_parts] == ([
             ('started_following_repo', 0),
@@ -374,7 +374,7 @@
     @parametrize_vcs_test
     def test_push_new_file(self, webserver, testfork, vt):
         UserLog.query().delete()
-        Session().commit()
+        meta.Session().commit()
 
         dest_dir = _get_tmp_dir()
         clone_url = vt.repo_url_param(webserver, vt.repo_name)
@@ -390,7 +390,7 @@
             assert 'Repository size' in stdout
             assert 'Last revision is now' in stdout
 
-        Session.close()  # make sure SA fetches all new log entries (apparently only needed for MariaDB/MySQL ...)
+        meta.Session.close()  # make sure SA fetches all new log entries (apparently only needed for MariaDB/MySQL ...)
         action_parts = [ul.action.split(':', 1) for ul in UserLog.query().order_by(UserLog.user_log_id)]
         assert [(t[0], (t[1].count(',') + 1) if len(t) == 2 else 0) for t in action_parts] == \
             [('pull', 0), ('push', 3)]
@@ -398,14 +398,14 @@
     @parametrize_vcs_test
     def test_pull(self, webserver, testfork, vt):
         UserLog.query().delete()
-        Session().commit()
+        meta.Session().commit()
 
         dest_dir = _get_tmp_dir()
         stdout, stderr = Command(base.TESTS_TMP_PATH).execute(vt.repo_type, 'init', dest_dir)
 
         clone_url = vt.repo_url_param(webserver, vt.repo_name)
         stdout, stderr = Command(dest_dir).execute(vt.repo_type, 'pull', clone_url)
-        Session.close()  # make sure SA fetches all new log entries (apparently only needed for MariaDB/MySQL ...)
+        meta.Session.close()  # make sure SA fetches all new log entries (apparently only needed for MariaDB/MySQL ...)
 
         if vt.repo_type == 'git':
             assert 'FETCH_HEAD' in stderr
@@ -454,7 +454,7 @@
         if vt.repo_type == 'git':
             _check_proper_git_push(stdout, stderr)
 
-        Session.close()  # expire session to make sure SA fetches new Repository instances after last_changeset has been updated by server side hook in another process
+        meta.Session.close()  # expire session to make sure SA fetches new Repository instances after last_changeset has been updated by server side hook in another process
         post_cached_tip = [repo.get_api_data()['last_changeset']['short_id'] for repo in Repository.query().filter(Repository.repo_name == testfork[vt.repo_type])]
         assert pre_cached_tip != post_cached_tip
 
@@ -476,7 +476,7 @@
     @parametrize_vcs_test
     def test_push_with_readonly_credentials(self, webserver, vt):
         UserLog.query().delete()
-        Session().commit()
+        meta.Session().commit()
 
         dest_dir = _get_tmp_dir()
         clone_url = vt.repo_url_param(webserver, vt.repo_name, username=base.TEST_USER_REGULAR_LOGIN, password=base.TEST_USER_REGULAR_PASS)
@@ -489,7 +489,7 @@
         elif vt.repo_type == 'hg':
             assert 'abort: HTTP Error 403: Forbidden' in stderr or 'abort: push failed on remote' in stderr and 'remote: Push access to %r denied' % str(vt.repo_name) in stdout
 
-        Session.close()  # make sure SA fetches all new log entries (apparently only needed for MariaDB/MySQL ...)
+        meta.Session.close()  # make sure SA fetches all new log entries (apparently only needed for MariaDB/MySQL ...)
         action_parts = [ul.action.split(':', 1) for ul in UserLog.query().order_by(UserLog.user_log_id)]
         assert [(t[0], (t[1].count(',') + 1) if len(t) == 2 else 0) for t in action_parts] == \
             [('pull', 0)]
@@ -516,7 +516,7 @@
         try:
             # Add IP constraint that excludes the test context:
             user_model.add_extra_ip(base.TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
-            Session().commit()
+            meta.Session().commit()
             # IP permissions are cached, need to wait for the cache in the server process to expire
             time.sleep(1.5)
             clone_url = vt.repo_url_param(webserver, vt.repo_name)
@@ -530,7 +530,7 @@
             # release IP restrictions
             for ip in UserIpMap.query():
                 UserIpMap.delete(ip.ip_id)
-            Session().commit()
+            meta.Session().commit()
             # IP permissions are cached, need to wait for the cache in the server process to expire
             time.sleep(1.5)
 
@@ -552,7 +552,7 @@
     def test_custom_hooks_preoutgoing(self, testhook_cleanup, webserver, testfork, vt):
         # set prechangegroup to failing hook (returns True)
         Ui.create_or_update_hook('preoutgoing.testhook', 'python:kallithea.tests.fixture.failing_test_hook')
-        Session().commit()
+        meta.Session().commit()
         # clone repo
         clone_url = vt.repo_url_param(webserver, testfork[vt.repo_type], username=base.TEST_USER_ADMIN_LOGIN, password=base.TEST_USER_ADMIN_PASS)
         dest_dir = _get_tmp_dir()
@@ -567,7 +567,7 @@
     def test_custom_hooks_prechangegroup(self, testhook_cleanup, webserver, testfork, vt):
         # set prechangegroup to failing hook (returns exit code 1)
         Ui.create_or_update_hook('prechangegroup.testhook', 'python:kallithea.tests.fixture.failing_test_hook')
-        Session().commit()
+        meta.Session().commit()
         # clone repo
         clone_url = vt.repo_url_param(webserver, testfork[vt.repo_type], username=base.TEST_USER_ADMIN_LOGIN, password=base.TEST_USER_ADMIN_PASS)
         dest_dir = _get_tmp_dir()
@@ -584,7 +584,7 @@
 
         # set prechangegroup hook to exception throwing method
         Ui.create_or_update_hook('prechangegroup.testhook', 'python:kallithea.tests.fixture.exception_test_hook')
-        Session().commit()
+        meta.Session().commit()
         # re-try to push
         stdout, stderr = Command(dest_dir).execute('%s push' % vt.repo_type, clone_url, ignoreReturnCode=True)
         if vt is HgHttpVcsTest:
@@ -599,7 +599,7 @@
 
         # set prechangegroup hook to method that returns False
         Ui.create_or_update_hook('prechangegroup.testhook', 'python:kallithea.tests.fixture.passing_test_hook')
-        Session().commit()
+        meta.Session().commit()
         # re-try to push
         stdout, stderr = Command(dest_dir).execute('%s push' % vt.repo_type, clone_url, ignoreReturnCode=True)
         assert 'passing_test_hook succeeded' in stdout + stderr