diff --git a/ckanext/datastore/db.py b/ckanext/datastore/db.py index 77054d73c88..002fa6f57d8 100644 --- a/ckanext/datastore/db.py +++ b/ckanext/datastore/db.py @@ -33,10 +33,10 @@ def __init__(self, error_dict): # See http://www.postgresql.org/docs/9.2/static/errcodes-appendix.html _PG_ERR_CODE = { - 'unique_violation': 23505, - 'query_canceled': 57014, - 'undefined_object': 42704, - 'syntax_error': 42601 + 'unique_violation': '23505', + 'query_canceled': '57014', + 'undefined_object': '42704', + 'syntax_error': '42601' } _date_formats = ['%Y-%m-%d', @@ -167,7 +167,7 @@ def _is_valid_pg_type(context, type_name): try: connection.execute('SELECT %s::regtype', type_name) except ProgrammingError, e: - if int(e.orig.pgcode) in [_PG_ERR_CODE['undefined_object'], + if e.orig.pgcode in [_PG_ERR_CODE['undefined_object'], _PG_ERR_CODE['syntax_error']]: return False raise @@ -969,7 +969,7 @@ def create(context, data_dict): trans.commit() return _unrename_json_field(data_dict) except IntegrityError, e: - if int(e.orig.pgcode) == _PG_ERR_CODE['unique_violation']: + if e.orig.pgcode == _PG_ERR_CODE['unique_violation']: raise ValidationError({ 'constraints': ['Cannot insert records or create index because ' 'of uniqueness constraint'], @@ -979,7 +979,7 @@ def create(context, data_dict): }) raise except DBAPIError, e: - if int(e.orig.pgcode) == _PG_ERR_CODE['query_canceled']: + if e.orig.pgcode == _PG_ERR_CODE['query_canceled']: raise ValidationError({ 'query': ['Query took too long'] }) @@ -1012,7 +1012,7 @@ def upsert(context, data_dict): trans.commit() return _unrename_json_field(data_dict) except IntegrityError, e: - if int(e.orig.pgcode) == _PG_ERR_CODE['unique_violation']: + if e.orig.pgcode == _PG_ERR_CODE['unique_violation']: raise ValidationError({ 'constraints': ['Cannot insert records or create index because ' 'of uniqueness constraint'], @@ -1022,7 +1022,7 @@ def upsert(context, data_dict): }) raise except DBAPIError, e: - if int(e.orig.pgcode) == _PG_ERR_CODE['query_canceled']: + if e.orig.pgcode == _PG_ERR_CODE['query_canceled']: raise ValidationError({ 'query': ['Query took too long'] }) @@ -1089,7 +1089,7 @@ def search(context, data_dict): }) return search_data(context, data_dict) except DBAPIError, e: - if int(e.orig.pgcode) == _PG_ERR_CODE['query_canceled']: + if e.orig.pgcode == _PG_ERR_CODE['query_canceled']: raise ValidationError({ 'query': ['Search took too long'] }) @@ -1122,7 +1122,7 @@ def search_sql(context, data_dict): } }) except DBAPIError, e: - if int(e.orig.pgcode) == _PG_ERR_CODE['query_canceled']: + if e.orig.pgcode == _PG_ERR_CODE['query_canceled']: raise ValidationError({ 'query': ['Query took too long'] })