You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide example of how to use the new package_revise #181
Let's say I have a dataset with name "MyDataset" I want to update, removing resources 0 and 2, updating the description of resource 1 and uploading a new file for resource 1. I understand from documentation that the parameters would be something like:
match = {"name":"MyDataset"}
filter = ["-resources__0", "-resources__2"]
update = {"resources__1__description": "My new description"}
update__resources__1__upload@/tmp/datafile.xlsx
Can you show in code how I pass those things in the call_action? For example, do they all go in the second parameter (data_dict) and if so, how does the file upload one go in there since it isn't a key value pair? Do I still need to use the "files" parameter?
The remote CKAN action API may be called in one of three ways:
GET request with string parameters
POST request with JSON body
multipart POST request with string parameters and file attachments
only number 3 can be used when uploading files, so JSON can't be used to nest the other parameter values sent as part of the same call. package_revise works around this by also accepting JSON as a string for the top level parameters. e.g.
myckan.call_action(
'package_revise',
{'match': '{"name":"MyDataset"}'}, # values need to be JSON strings when uploading filesfiles={'update__resources__1__upload': myfile},
)
I could update ckanapi to automatically convert lists and dictionaries at the top level of multipart POST requests to their JSON versions, but as far as I know only package_revise accepts this automatically.
@ghostpackage_revise is safe, because it allows concurrent calls, whereas resource_create may result in data loss if other actions (including package_revise) are changing the dataset/package at the same time.
[EDIT: I guess it's the right time here to talk to ghosts]
Activity
wardi commentedon Feb 1, 2021
The remote CKAN action API may be called in one of three ways:
only number 3 can be used when uploading files, so JSON can't be used to nest the other parameter values sent as part of the same call.
package_reviseworks around this by also accepting JSON as a string for the top level parameters. e.g.I could update ckanapi to automatically convert lists and dictionaries at the top level of multipart POST requests to their JSON versions, but as far as I know only
package_reviseaccepts this automatically.mcarans commentedon Feb 3, 2021
Thanks! Is there any reason to use package_update any more?
wardi commentedon Feb 4, 2021
no, but
package_updatedoes have a simpler interface for replacing all the metadata fields in a dataset.paulmueller commentedon Sep 2, 2021
@ghost
package_reviseis safe, because it allows concurrent calls, whereasresource_createmay result in data loss if other actions (includingpackage_revise) are changing the dataset/package at the same time.[EDIT: I guess it's the right time here to talk to ghosts]