ckan / ckanext-spatial

Geospatial extension for CKAN
http://docs.ckan.org/projects/ckanext-spatial
126 stars 193 forks source link

CSW client code fails to process MI_Metadata #209

Open benjwadams opened 5 years ago

benjwadams commented 5 years ago

Attempting to harvest from a CSW with ISO metadata starting with MI_Metadata, rather than MD_Metadata fails:

https://github.com/ckan/ckanext-spatial/blob/master/ckanext/spatial/lib/csw_client.py#L178-L189

Essentially, the call to .find does not find MD_Metadata, and so returns None, which gets propagated down to this line:

record["xml"] = '<?xml version="1.0" encoding="UTF-8"?>\n' + record["xml"]

This raises an exception since concatenating a string with None is not a valid operation. This could be fairly easily fixed by adding in the MI_Metadata as a valid element to find as well. In fact, it looks like the data.gov fork of ckanext-spatial does just that: https://github.com/GSA/ckanext-spatial/blob/datagov/ckanext/spatial/lib/csw_client.py#L171 Additionally, cases in which root elements which weren't MD_Metadata or MI_Metadata should be handled early so that a sane error message is raised, rather than an error about concatenating string to None, which does not make the reason for failure particularly clear .

benjwadams commented 5 years ago

Related #210