Skip to content

Commit

Permalink
[QOLDEV-347] fix validation errors on empty strings, ckan#182
Browse files Browse the repository at this point in the history
- replace empty strings with None if they have types that will choke on empty string
  • Loading branch information
ThrawnCA committed Apr 17, 2023
1 parent 9f96e16 commit cf04a5c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ckanext/xloader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,16 @@ def row_iterator():

logger.info('Copying to database...')
count = 0
# Some types cannot be stored as empty strings and must be converted to None,
# https://github.com/ckan/ckanext-xloader/issues/182
non_empty_types = ['timestamp', 'numeric']
for i, records in enumerate(chunky(result, 250)):
count += len(records)
logger.info('Saving chunk {number}'.format(number=i))
for row in records:
for column_index, column_name in enumerate(row):
if headers_dicts[column_index]['type'] in non_empty_types and row[column_name] == '':
row[column_name] = None
send_resource_to_datastore(resource_id, headers_dicts, records)
logger.info('...copying done')

Expand Down

0 comments on commit cf04a5c

Please sign in to comment.