Skip to content

Groups/Organizations silently ignore create_validators #404

@themowski

Description

@themowski

ckanext-scheming version: release-3.0.0

My team would like the name field to be automatically generated and match the id field for our CKAN Groups. We previously got this working for Datasets using the guidance that was posted in response to our CKAN discussion forum post.

I tried implementing the same approach for Groups, but it did not work [1]. I looked at the ckanext-scheming code and discovered that create_validators is not supported in a Group schema (and it is silently ignored if specified). The relevant portion of _GroupOrganizationMixin.validate() is:

get_validators = (
_field_output_validators_group
if action_type == 'show' else _field_validators
)

The mixin provides support for output_validators, but not create_validators. Compare to the implementation in SchemingDatasetsPlugin.validate(), which has the logic required for dataset (package) schema parsing:

before = scheming_schema.get('before_validators')
after = scheming_schema.get('after_validators')
if action_type == 'show':
get_validators = _field_output_validators
before = after = None
elif action_type == 'create':
get_validators = _field_create_validators
else:
get_validators = _field_validators

It looks like patching this in is non-trivial... as shown in the code snippets above, in the Group/Org case, there is a separate function called _field_output_validators_group() that wraps _field_output_validators() (used in the Dataset/Package case) and specifies the value of the latter's convert_from_extras_type argument. This input argument is not part of the signature of _field_create_validators(), and it's not clear to me if it needs to be.


[1] On an unrelated note, my team ended up accomplishing what we needed by:

It's not as clean as having support for create_validators, but it seems to be working as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions