[ckan-dev] Schema Validation (show_group)
Sean Hammond
sean.hammond at okfn.org
Wed Aug 8 09:02:42 UTC 2012
> Could someone please clarify the purpose of
> ckan.lib.navl.dictization_functions.validate
>
> My limited understanding was that it is used to validate/clean data used
> in saving objects via forms/api etc this seems reasonable even if I
> don't like the way that it changes the passed dict - but that's another
> story.
That's my understand also, but not just for saving objects, any data
passed into CKAN.
> It however is also used in some of the show logic actions -
> related_show, package_show (only if validate: True is set in the
> context), most of the follower gets
Yes. This is consistent, isn't it? You have to pass a data dict to some
of the show logic actions, e.g. package_show needs a dict with the
package name or id like {"id": "foobar"}. I don't what the validate:
True in the context is about.
> It is used in group_show but was being discarded Sean's commit
> e9b4f65c4014ce4 fixed this but has 'broken' the demo site as this causes
> the groups package dict to be stripped from the full package info to
> just name and title. We were using this to display group packages on the
> home page and want the notes.
Hmm. By default DefaultGroupForm would return None for the
db_to_form_schema so no validation would happen in group_show. Do you
have organizations enabled? If so then you'll get group_form_schema()
from ckan/logic/schema.py, and presumably that's what is stripping your
dataset dicts. So I think the right fix for your issue would be to
change group_form_schema() so that it doesn't strip the dataset info.
> From my point of view this is a regression and should at minimum be
> activated via a context option.
If you think it's good to have group_show always return all the full
dataset dicts in the group dict, then I'd suggest changing
group_form_schema seems to be the right thing to do.
> 1) why are we validating in the logic action gets?
You have to pass a data dict containing the package id, group id, or
whatever id of the object you're getting, some of the logic action gets
accept other data as well (e.g. search query) so the get functions do
accept data (even if it is not data that's gonna be saved into the db)
and will have to 'validate' that data in some way, may as well use the
same way as the creates and updates.
> 2) why is it not done consistently?
It should be consistent imo, but I know that some of the logic action
functions do no validation, others have their own custom validation code
rather than using CKAN's schema system. Better for everything to use the
schemas I think, simply for consistency.
> 3) what are we going to do with group_show specifically?
See above
More information about the ckan-dev
mailing list