ckan / ckan/ckanext-spatial

crash when parsing custom validators

Open
#277 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
XSLT
Stars
136
Forks
207
PR merge metrics
No merged PRs in 30d

Description

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:

```python
# 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](https://docs.ckan.org/en/2.9/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IValidators.get_validators). 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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in ckanext/spatial/harvesters/base.py at SpatialHarvester._get_validator(), especially the custom-validator loop around line 790. Reproduce the crash with a plugin that provides validators while also customizing harvester behavior, then check the existing CKAN validator interface expectations. Done means custom validators are accepted without the parsing crash and the relevant validation behavior remains functional.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.