ckan / ckanext-spatial

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

crash when parsing custom validators #277

Open ricardogsilva opened 2 years ago

ricardogsilva commented 2 years ago

There is a bug in ckanext.spatial.harvesters.base.SpatialHarvester._get_validator()

https://github.com/ckan/ckanext-spatial/blob/09fbc27054f5d2f41238d858b018fca94a7c4c0d/ckanext/spatial/harvesters/base.py#L790

This is a verbatim copy of the code that is currently in master:

# Add any custom validators from extensions
for plugin_with_validators in p.PluginImplementations(ISpatialHarvester):
    custom_validators = plugin_with_validators.get_validators()
    for custom_validator in custom_validators:
        if custom_validator not in all_validators:
            self._validator.add_validator(custom_validator)

In the above snippet, the custom_validators variable is a Python dictionary, as documented in the CKAN docs. The problem is that the nested for loop is iterating over the dictionary keys, which are strings, and then passes each item to self._validator.add_validator, which expects to receive a class instance instead - which by the way is also bugged, as current versions of CKAN allow using regular functions as validators.

I'm guessing this is something left behind from when CKAN moved to Flask from Pylons?

Unfortunately this is something that prevents using custom validators and customizing a harvester behavior at the same time in the same plugin class.