Skip to content

Commit

Permalink
[#1714] do not remove session when get_site_user is called
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joetsoi committed Jul 24, 2014
1 parent 8418ff5 commit e7540e2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 1 addition & 3 deletions ckan/lib/cli.py
Expand Up @@ -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'))
Expand Down
7 changes: 3 additions & 4 deletions ckan/logic/action/get.py
Expand Up @@ -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)
Expand All @@ -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}
Expand Down
1 change: 1 addition & 0 deletions ckan/model/__init__.py
Expand Up @@ -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).*')
Expand Down

0 comments on commit e7540e2

Please sign in to comment.