[ckan-dev] IDatasetForm: form_to_db_schema_api_create() etc

Sean Hammond sean.hammond at okfn.org
Fri Mar 15 15:36:52 UTC 2013


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




More information about the ckan-dev mailing list