[ckan-dev] IDatasetForm: form_to_db_schema_api_create() etc

Toby Dacre toby.okfn at gmail.com
Fri Mar 15 15:51:41 UTC 2013


On 15 March 2013 15:36, Sean Hammond <sean.hammond at okfn.org> wrote:
> Hey,
>
> The IDatasetForm plugin interface has a method:
>
>     def form_to_db_schema(self):
>         '''Return the schema for mapping dataset dicts from form to db.
>
>         CKAN will use the returned schema to validate and convert data coming
>         from users (via the dataset form) before entering that data into the
>         database.
>
>         ...
>
> But what really happens is:
>
> - If creating or updating a dataset using the web interface,
>   form_to_db_schema() is called
> - If creating a dataset using the API form_to_db_schema_api_create()
>   is called instead
> - If updating a dataset using the API form_to_db_schema_api_update()
>   is called instead
>
> This only happens if your IDatasetForm plugin inherits from
> DefaultDatasetForm, if it doesn't then form_to_db_schema() is called in
> all three cases.
>
> This logic (selecting when to call form_to_db_schema(),
> form_to_db_schema_api_update() or form_to_db_schema_api_create()) seems
> like it probably belongs in CKAN's logic functions not in a
> form_to_db_schema_options() method in DefaultDatasetForm.
>
> We need to either document form_to_db_schema_options(), _api_create()
> and _api_update() in IDatasetForm, or we need to get rid of the whole
> lot and just call form_to_db_schema() always.
>
> (There's also db_to_form_schema_options() which is also missing from
> IDatasetForm.)
>
> Do we really want to support using different schemas for different
> purposes - web UI vs API, create vs update? It seems that in most cases
> people will want and expect the same schema always. I'm not sure what
> the use-case for this is.
>
> If I'm not mistaken this seems to be the commit that added this feature
> (but that doesn't shed much light on things):
>
> https://github.com/okfn/ckan/commit/6f743b636001f6f78f40b0dc9a53cffdd972c851
>

I am indeed responsible for this sick twistedness.  This stems from
various things.  Essentially this is due to the change from the all in
one dataset creation of 1.8 and the 3 stage 2.0.  The thing is that
changing the schema to allow partial creation for the front-end broke
lots of tests among other things.

I think that we should do the following.

have a `create` and an `update` schema that is used by both the api
and the front end it is stupid to have data counted as ok one way but
not the other.  Hopefully the allow partial updates stuff done will
help here - before the data would get stripped out of datasets if not
supplied.

this just feels the way we should do things - maybe we could even get
to a single schema not even a create/update

kill the old template tests and replace with new template based front
end testing

clean up the IDatasetForm to deprecate and then kill all these extra methods.

Toby

> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev




More information about the ckan-dev mailing list