Skip to content

Commit

Permalink
Don't a 500 when printing the validation errors.
Browse files Browse the repository at this point in the history
If there's no 'resources' key, or the error is on a different resource,
just prints the base error_dict.
  • Loading branch information
CarlQLange committed May 18, 2016
1 parent 32375f2 commit 38551aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ckan/logic/action/create.py
Expand Up @@ -300,8 +300,10 @@ def resource_create(context, data_dict):
_get_action('package_update')(context, pkg_dict)
context.pop('defer_commit')
except ValidationError, e:
errors = e.error_dict['resources'][-1]
raise ValidationError(errors)
try:
raise ValidationError(e.error_dict['resources'][-1])
except (KeyError, IndexError):
raise ValidationError(e.error_dict)

## Get out resource_id resource from model as it will not appear in
## package_show until after commit
Expand Down
6 changes: 4 additions & 2 deletions ckan/logic/action/update.py
Expand Up @@ -98,8 +98,10 @@ def resource_update(context, data_dict):
updated_pkg_dict = _get_action('package_update')(context, pkg_dict)
context.pop('defer_commit')
except ValidationError, e:
errors = e.error_dict['resources'][n]
raise ValidationError(errors)
try:
raise ValidationError(e.error_dict['resources'][-1])
except (KeyError, IndexError):
raise ValidationError(e.error_dict)

upload.upload(id, uploader.get_max_resource_size())
model.repo.commit()
Expand Down

0 comments on commit 38551aa

Please sign in to comment.