From 61ffef8688a37040bc4a8e392346bc5532ed21b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Dvo=C5=99=C3=A1k?= Date: Thu, 10 Mar 2016 20:13:40 +0100 Subject: [PATCH] datastore: use repr() for log message ascii-safety MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Logging statements had a potential to crash on unicode inputs. Make sure they are always escaped. Signed-off-by: Jan Dvořák --- ckanext/datastore/db.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/ckanext/datastore/db.py b/ckanext/datastore/db.py index fa4cd9f20ea..7a339591f89 100644 --- a/ckanext/datastore/db.py +++ b/ckanext/datastore/db.py @@ -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 = { @@ -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( @@ -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): @@ -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 @@ -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() @@ -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()