# HG changeset patch # User Mads Kiilerich # Date 2020-03-17 17:15:59 # Node ID 2fa9f497faacf13a2a6e8438f85abeea4ca83a92 # Parent e98f6338829cc795ce067c8c4ec6831887b890cc repos: separate repo creation from form validation The broad catching of Exception in the repo creation controller is conceptually bad. It also caused misleading "Error creating repository None" when form validation failed with anything but formencode.Invalid . For now, just constrain the broad exception handling to only cover repo creation. It is a bug if form validation fails in unexpected ways, and we want it reported as a crash that we can fix. diff --git a/kallithea/controllers/admin/repos.py b/kallithea/controllers/admin/repos.py --- a/kallithea/controllers/admin/repos.py +++ b/kallithea/controllers/admin/repos.py @@ -112,17 +112,11 @@ class ReposController(BaseRepoController @NotAnonymous() def create(self): self.__load_defaults() - form_result = {} try: # CanWriteGroup validators checks permissions of this POST form_result = RepoForm(repo_groups=c.repo_groups, landing_revs=c.landing_revs_choices)() \ .to_python(dict(request.POST)) - - # create is done sometimes async on celery, db transaction - # management is handled there. - task = RepoModel().create(form_result, request.authuser.user_id) - task_id = task.task_id except formencode.Invalid as errors: log.info(errors) return htmlfill.render( @@ -133,6 +127,11 @@ class ReposController(BaseRepoController force_defaults=False, encoding="UTF-8") + try: + # create is done sometimes async on celery, db transaction + # management is handled there. + task = RepoModel().create(form_result, request.authuser.user_id) + task_id = task.task_id except Exception: log.error(traceback.format_exc()) msg = (_('Error creating repository %s')