Skip to content

Commit

Permalink
datastore: use repr() for log message ascii-safety
Browse files Browse the repository at this point in the history
Logging statements had a potential to crash on unicode inputs.
Make sure they are always escaped.

Signed-off-by: Jan Dvořák <mordae@anilinux.org>
  • Loading branch information
mordae authored and amercader committed Mar 16, 2016
1 parent 3656f0e commit 61ffef8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ckanext/datastore/db.py
Expand Up @@ -123,7 +123,7 @@ def _cache_types(context):
if 'nested' not in _type_names:
native_json = _pg_version_is_at_least(connection, '9.2')

log.info("Create nested type. Native JSON: {0}".format(
log.info("Create nested type. Native JSON: {0!r}".format(
native_json))

data_dict = {
Expand Down Expand Up @@ -434,7 +434,7 @@ def create_indexes(context, data_dict):
if field not in field_ids:
raise ValidationError({
'index': [
(u'The field "{0}" is not a valid column name.').format(
u'The field "{0}" is not a valid column name.'.format(
index)]
})
fields_string = u', '.join(
Expand Down Expand Up @@ -1216,7 +1216,7 @@ def search_sql(context, data_dict):
u'SET LOCAL statement_timeout TO {0}'.format(timeout))

table_names = datastore_helpers.get_table_names_from_sql(context, sql)
log.debug('Tables involved in input SQL: {0}'.format(table_names))
log.debug('Tables involved in input SQL: {0!r}'.format(table_names))

system_tables = [t for t in table_names if t.startswith('pg_')]
if len(system_tables):
Expand Down Expand Up @@ -1274,15 +1274,18 @@ def _change_privilege(context, data_dict, what):
read_only_user)
else:
raise ValidationError({
'privileges': [u'Can only GRANT or REVOKE but not {0}'.format(what)]
'privileges': [
u'Can only GRANT or REVOKE but not {0}'.format(what)
]
})
try:
context['connection'].execute(sql)
except ProgrammingError, e:
log.critical("Error making resource private. {0}".format(e.message))
log.critical("Error making resource private. {0!r}".format(e.message))
raise ValidationError({
'privileges': [u'cannot make "{0}" private'.format(
data_dict['resource_id'])],
'privileges': [
u'cannot make "{resource_id}" private'.format(**data_dict)
],
'info': {
'orig': str(e.orig),
'pgcode': e.orig.pgcode
Expand All @@ -1291,8 +1294,7 @@ def _change_privilege(context, data_dict, what):


def make_private(context, data_dict):
log.info('Making resource {0} private'.format(
data_dict['resource_id']))
log.info('Making resource {resource_id!r} private'.format(**data_dict))
engine = _get_engine(data_dict)
context['connection'] = engine.connect()
trans = context['connection'].begin()
Expand All @@ -1304,8 +1306,7 @@ def make_private(context, data_dict):


def make_public(context, data_dict):
log.info('Making resource {0} public'.format(
data_dict['resource_id']))
log.info('Making resource {resource_id!r} public'.format(**data_dict))
engine = _get_engine(data_dict)
context['connection'] = engine.connect()
trans = context['connection'].begin()
Expand Down

0 comments on commit 61ffef8

Please sign in to comment.