Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix output validators parsing when repeating_subfields #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spwoodcock
Copy link

@spwoodcock spwoodcock commented Aug 4, 2023

Error

Currently if repeating_subfields are used with an output_validator, then an error is raised during validator concatenation:

2023-08-04 07:28:58,146.146 [ERROR] ckan.lib.search | rebuild:210 | Traceback (most recent call last):
  File "/usr/lib/ckan/.local/lib/python3.9/site-packages/ckan/lib/search/__init__.py", line 200, in rebuild
    package_index.update_dict(
  File "/usr/lib/ckan/.local/lib/python3.9/site-packages/ckan/lib/search/index.py", line 109, in update_dict
    self.index_package(pkg_dict, defer_commit)
  File "/usr/lib/ckan/.local/lib/python3.9/site-packages/ckan/lib/search/index.py", line 127, in index_package
    validated_pkg_dict, errors = lib_plugins.plugin_validate(
  File "/usr/lib/ckan/.local/lib/python3.9/site-packages/ckan/lib/plugins.py", line 312, in plugin_validate
    result = plugin.validate(context, data_dict, schema, action)
  File "/usr/lib/ckan/.local/lib/python3.9/site-packages/ckanext/scheming/plugins.py", line 264, in validate
    destination[f['field_name']] = get_validators(
  File "/usr/lib/ckan/.local/lib/python3.9/site-packages/ckanext/scheming/plugins.py", line 577, in _field_output_validators
    validators += validation.validators_from_string(
TypeError: unsupported operand type(s) for +=: 'dict' and 'list'

Issue

The source of the error (trying to add dict subfield validators to list of field validators):

if 'output_validators' in f:
validators += validation.validators_from_string(
f['output_validators'], f, schema)

Solution

This PR adds a type check and appends the field validator as a list if no subfields, or as a dict if subfields:

    if 'output_validators' in f:
        if isinstance(validators, list):
            validators += validation.validators_from_string(
                f['output_validators'], f, schema
            )
        else:
            validators.update({
                f['field_name']: validation.validators_from_string(
                f['output_validators'], f, schema
            )})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant