Skip to content

Commit

Permalink
Merge pull request #1714 from ckan/1714-fix-get-site-user
Browse files Browse the repository at this point in the history
`get_site_user` performs a commit on each call
  • Loading branch information
David Read committed Aug 8, 2014
2 parents d9e6240 + e7540e2 commit 1f46559
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 @@ -2140,8 +2140,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 @@ -2160,8 +2159,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 1f46559

Please sign in to comment.