Skip to content

Commit

Permalink
[#838] Postgres error codes are five character strings, not integers
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Apr 28, 2013
1 parent f895097 commit f6fb1b7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions ckanext/datastore/db.py
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'],
Expand All @@ -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']
})
Expand Down Expand Up @@ -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'],
Expand All @@ -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']
})
Expand Down Expand Up @@ -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']
})
Expand Down Expand Up @@ -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']
})
Expand Down

0 comments on commit f6fb1b7

Please sign in to comment.