Skip to content

Commit

Permalink
[#2804] Raise ValidationError for long column headings in Datastore
Browse files Browse the repository at this point in the history
Postgres has a limit of 63 characters for column names.

When a resource is inserted in Datastore, if it contains column headings that have names longer than 63 characters a ValidationError is raised showing affected columns.
  • Loading branch information
Aleksandar Jovanov committed Jun 17, 2017
1 parent 54d6c9b commit ca8c004
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ckanext/datastore/backend/postgres.py
Expand Up @@ -855,6 +855,20 @@ def create_table(context, data_dict):
field_ids = _pluck('id', supplied_fields)
records = data_dict.get('records')

fields_errors = []

for field_id in field_ids:
# Postgres has a limit of 63 characters for a column name
if len(field_id) > 63:
message = 'Column heading "{0}" exceeds limit of 63 '\
'characters.'.format(field_id)
fields_errors.append(message)

if fields_errors:
raise ValidationError({
'fields': fields_errors
})

# if type is field is not given try and guess or throw an error
for field in supplied_fields:
if 'type' not in field:
Expand Down

0 comments on commit ca8c004

Please sign in to comment.