From e7540e25805587029e25efbd2a09b94cd20189a5 Mon Sep 17 00:00:00 2001 From: joetsoi Date: Thu, 24 Jul 2014 11:32:45 +0100 Subject: [PATCH] [#1714] do not remove session when get_site_user is called Only commit if the site user is created. Change clean_db so that it commits and removes the session so that any open transactions that might cause clean_db to hang are closed before dropping the tables. --- ckan/lib/cli.py | 4 +--- ckan/logic/action/get.py | 7 +++---- ckan/model/__init__.py | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ckan/lib/cli.py b/ckan/lib/cli.py index 34d2c86f700..a9e2c7d7e6e 100644 --- a/ckan/lib/cli.py +++ b/ckan/lib/cli.py @@ -147,12 +147,10 @@ def _load_config(self): self.registry.register(pylons.c, c) - self.site_user = logic.get_action('get_site_user')({'ignore_auth': True, - 'defer_commit': True}, {}) + self.site_user = logic.get_action('get_site_user')({'ignore_auth': True}, {}) pylons.c.user = self.site_user['name'] pylons.c.userobj = model.User.get(self.site_user['name']) - model.repo.commit_and_remove() ## give routes enough information to run url_for parsed = urlparse.urlparse(conf.get('ckan.site_url', 'http://0.0.0.0')) diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index 913a8e9323c..85b1ae54d6f 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -2091,8 +2091,7 @@ def get_site_user(context, data_dict): '''Return the ckan site user :param defer_commit: by default (or if set to false) get_site_user will - commit and clean up the current transaction, it will also close and - discard the current session in the context. If set to true, caller + commit and clean up the current transaction. If set to true, caller is responsible for commiting transaction after get_site_user is called. Leaving open connections can cause cli commands to hang! (optional, default: False) @@ -2111,8 +2110,8 @@ def get_site_user(context, data_dict): user.sysadmin = True model.Session.add(user) model.Session.flush() - if not context.get('defer_commit'): - model.repo.commit_and_remove() + if not context.get('defer_commit'): + model.repo.commit() return {'name': user.name, 'apikey': user.apikey} diff --git a/ckan/model/__init__.py b/ckan/model/__init__.py index a0963b54faa..b9fc28921b8 100644 --- a/ckan/model/__init__.py +++ b/ckan/model/__init__.py @@ -231,6 +231,7 @@ def init_db(self): log.info('Database initialised') def clean_db(self): + self.commit_and_remove() meta.metadata = MetaData(self.metadata.bind) with warnings.catch_warnings(): warnings.filterwarnings('ignore', '.*(reflection|tsvector).*')