[#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:
parent
85a013f2c9
commit
01df3a1db4
|
@ -254,10 +254,16 @@ 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):
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue