ckan / ckan/ckanext-scheming

Groups/Organizations silently ignore `create_validators`

Open
#404 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
102
Forks
182
PR merge metrics
No merged PRs in 30d

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](https://github.com/ckan/ckan/discussions/8091).

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:

https://github.com/ckan/ckanext-scheming/blob/8d62a28370c4f231dbf2f9688ede93a0356410e3/ckanext/scheming/plugins.py#L180-L183

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:

https://github.com/ckan/ckanext-scheming/blob/8d62a28370c4f231dbf2f9688ede93a0356410e3/ckanext/scheming/plugins.py#L239-L247

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](https://github.com/open-data/ckanext-canada/blob/69b04b8eaf2750b3e95239783d2768248240e10e/ckanext/canada/validators.py#L144-L154) 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 CKAN `group_id_exists()` validator](https://github.com/ckan/ckan/blob/ckan-2.10.1/ckan/logic/validators.py#L324-L335).
* 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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in ckanext/scheming/plugins.py with _GroupOrganizationMixin.validate(), _field_output_validators_group(), and _field_create_validators(), then compare them with SchemingDatasetsPlugin.validate(). Trace how create_validators and output_validators are parsed for Groups and Organizations, including convert_from_extras_type, and inspect any nearby validation tests. Done means Group and Organization schemas apply create_validators consistently without breaking existing output validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.