Skip to content

Commit

Permalink
[#1871] Remove EXPLAIN bits from error messages
Browse files Browse the repository at this point in the history
As we are running the EXPLAIN command to look for table names before the
actual command, if there is a syntax error, table does not exist, etc,
the error messages will include the EXPLAIN statement, not the one provided.

We remove the EXPLAIN bit from the statement before raising the
exception to avoid confusion.
  • Loading branch information
amercader committed Aug 5, 2014
1 parent d51a6e3 commit b042e61
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ckanext/datastore/db.py
Expand Up @@ -1183,12 +1183,17 @@ def search_sql(context, data_dict):
raise toolkit.NotAuthorized({
'permissions': ['Not authorized to read resource.']
})

def _remove_explain(msg):
return (msg.replace('EXPLAIN (FORMAT JSON) ', '')
.replace('EXPLAIN ', ''))

raise ValidationError({
'query': [str(e)],
'query': [_remove_explain(str(e))],
'info': {
'statement': [e.statement],
'statement': [_remove_explain(e.statement)],
'params': [e.params],
'orig': [str(e.orig)]
'orig': [_remove_explain(str(e.orig))]
}
})
except DBAPIError, e:
Expand Down

0 comments on commit b042e61

Please sign in to comment.