-
Notifications
You must be signed in to change notification settings - Fork 177
Description
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:
ckanext-scheming/ckanext/scheming/plugins.py
Lines 180 to 183 in 8d62a28
| 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:
ckanext-scheming/ckanext/scheming/plugins.py
Lines 239 to 247 in 8d62a28
| 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:
- Creating a modified version of the
canada_validate_generate_uuid()validator mentioned in the CKAN GitHub discussion linked above that makes sure that the generated ID does not match any existing Group. This uses the lookup logic from the core CKANgroup_id_exists()validator. - Using this validator in the regular
validators:block of our Group schema.
It's not as clean as having support for create_validators, but it seems to be working as expected.