[ckan-dev] Conditional validation on custom Datasets

Richard Claydon richard at icdw.co.uk
Tue Mar 4 12:39:24 UTC 2014


Hi

I have a requirement to not validate custom data on a package when a
package is created, only to validate when the package is updated. I
have achieved this by creating a custom form derived from
DefaultDatasetForm, adding the relevant rules in
create_package_schema() and update_package_schema().

So far so good.

The problem I am currently facing is, when I add a resource, the
package is validated because the package_update action is called
within the resource_create function inside actions/create.py.
Unfortunately the exception handler in resource_create assumes the
problem is with the resources and an unhandled KeyError exception is
thrown. Here is the code in CKAN.

    try:
        context['defer_commit'] = True
        context['use_cache'] = False
        _get_action('package_update')(context, pkg_dict)
        context.pop('defer_commit')
    except ValidationError, e:
        errors = e.error_dict['resources'][-1] # <--- assumes
validation error is in the resource.
        raise ValidationError(errors)

My question is; can anyone suggest how I can suppress package
validation when a resource is added? Resource validation is fine, but
the "new_resource" view in CKAN by default does not include the rest
of the package data, so IMO that shouldn't be validated here.

I would like to try and avoid overriding core code if possible.

Open to suggestions!

Thanks
Richard



More information about the ckan-dev mailing list