[#42] Dump non-string extras with json

Convert any non-string extra values to strings using json.dumps(),
instead of just deleting them.
This commit is contained in:
Sean Hammond 2013-05-31 20:35:06 +02:00
parent 85a013f2c9
commit 01df3a1db4
1 changed files with 9 additions and 3 deletions

View File

@ -254,11 +254,17 @@ class CKANHarvester(HarvesterBase):
package_dict['groups'] = []
package_dict['groups'].extend([g for g in default_groups if g not in package_dict['groups']])
# Delete any extras whose values are not strings, as these cause
# errors from CKAN when trying to create/update the package.
# Find any extras whose values are not strings and try to convert
# them to strings, as non-string extras are not allowed anymore in
# CKAN 2.0.
for key in package_dict['extras'].keys():
if not isinstance(package_dict['extras'][key], basestring):
del package_dict['extras'][key]
try:
package_dict['extras'][key] = json.dumps(
package_dict['extras'][key])
except TypeError:
# If converting to a string fails, just delete it.
del package_dict['extras'][key]
# Set default extras if needed
default_extras = self.config.get('default_extras',{})