[ckan-dev] Updating group via API clears its packages
David Read
david.read at hackneyworkshop.com
Mon Sep 17 17:30:17 UTC 2012
On 17 September 2012 10:48, Sean Hammond <sean.hammond at okfn.org> wrote:
>> Over at http://hub.healthdata.gov we're populating site data
>> entirely through the API. I'm now creating groups. I found that when
>> I update a group, any packages previously contained in the group are
>> no longer associated with the group.
I think because this API is RESTful, when you update an object then
you update everything about it in one go. You can't pick and choose
bits to update. That is the inflexibility / simplicity of RESTful
APIs. It's just like a file on a disk - if you open() and write(),
then you replace whatever was there before.
In contrast, the normal way to update in the RESTful world is to GET
the object, edit the bits you are interested in and then PUT it back.
So as long as you don't delete the list of packages in your copy of
the object then you are ok. (Although there is another issue, that
other edits submitted in the meantime do get overwritten, but lets not
get into "file locks"...)
So this is one of the reasons that the Action API was produced, that
Sean mentions. It's RPC, and a lot more flexible. I've not checked,
but if there is not a function to edit just the Group's core
properties (i.e. not the packages in it or user memberships) then that
it is sorely lacking.
Dave
>>
>> Is that the expected behavior?
>
> That's the current behaviour, yes. I'm not sure whether it was
> implemented that way for a reason. Personally I think it would be better
> if, when updating a dataset via the API, if for example no 'groups' key
> is passed with the dataset dict then the dataset's groups should not be
> changed. Seems more intuitive and makes the API more convenient to use.
> And your argument about not having to post thousands of packages in the
> data for simple updates is good also.
>
> Or if we're going to stick with the current behaviour we should
> certainly explain it in the package_update docstring.
>
> This goes for other updates as well, e.g. group_update, etc.
>
> What do others think about this?
>
> By the way, I recommend using v3 of the CKAN API as it's more complete
> and (since CKAN 1.8) has a better docs:
>
> http://docs.ckan.org/en/ckan-1.8/apiv3.html
>
> P.S. We'll try to look at your GitHub pull request as soon as we can
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
More information about the ckan-dev
mailing list