-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package_update deletes resource, some unspecified tags #108
Comments
Hi @moman822, the (best) way to update a package is to first get the package data, then update fields as required, then update the package with the updated original data. Hope this helps! |
@florianm can you show (or point to) a brief example of what you mean? Do you mean somehow updating the package data locally first? Thanks. |
@moman822 here's what I'd do: # Step 1: get the dataset details as R list
ds_id <- "my-dataset-id-md5-hash"
ds <- ckanr::package_show(ds_id)
# Step 2: update selected fields
ds$title <- "An updated title"
ds$description <- "I have updated title and description, while leaving all other fields unchanged."
# ds contains all other package data, including tags and resources
# Step 3: Update the dataset on CKAN with the locally modified list
result <- ckanr::package_update(ds, ds_id) Does this work for you? |
closing due to inactivity |
Hi, I had this same issue, and I think that is actually a bug that must be fixed. As you can read in the documentation pdf file, page 42, the approach is to include in the list just the fields you want to update. Please see this text from the documentation (https://cran.r-project.org/web/packages/ckanr/ckanr.pdf):
|
@fernandobarbalho What is a bug? you said "that", but what is "that"? |
Sorry, I wasn´t so clear. |
If I may offer my opinion, the "delete what's not included" behaviour feels logical. Updating the package with a dict implies that the dict contains the entire package metadata. The dict returned by As an approach to prevent unintended data loss, maybe the package_list help could expand more on this topic? package_update replaces all package metadata with the entire dict, and only the dict. Any data present in the package but not in the dict will be dropped. To add package metadata and retain the existing package metadata:
To replace package metadata with new data and drop any other existing package metadata:
Examples:
@fernandobarbalho @moman822 if the help for |
Yes, it would be perfect.
Thanks for your answer.
…________________________________
From: Florian Mayer <[email protected]>
Sent: Monday, April 15, 2019 11:04:08 PM
To: ropensci/ckanr
Cc: Fernando Almeida Barbalho; Mention
Subject: Re: [ropensci/ckanr] package_update deletes resource, some unspecified tags (#108)
If I may offer my opinion, the "delete what's not included" behaviour feels logical. Updating the package with a dict implies that the dict contains the entire package metadata. The dict returned by package_show contains (for free and in one command) all package metadata and is easier to manipulate than starting from scratch with an empty dict and having to get all the structure correct (I'm not good at this, especially when under-caffeinated, so package_show saved my bacon more than once).
As an approach to prevent unintended data loss, maybe the package_list help could expand more on this topic?
e.g. something along the lines of:
package_update replaces all package metadata with the entire dict, and only the dict. Any data present in the package but not in the dict will be dropped.
To add package metadata and retain the existing package metadata:
* get the current package metadata with package_show
* modify and/or add to the package metadata
* update the package with the package metadata
To replace package metadata with new data and drop any other existing package metadata:
* create a new package metadata dict, or get the current metadata and remove items from it
* update the package metadata
Examples:
## Update existing package metadata
# Step 1: get the dataset details as R list
ds_id <- "my-dataset-id-md5-hash"
ds <- ckanr::package_show(ds_id)
# Step 2: update selected fields
ds$title <- "An updated title"
ds$description <- "I have updated title and description, while leaving all other fields unchanged."
# ds contains all other package data, including tags and resources
# Step 3: Update the dataset on CKAN with the locally modified list
result <- ckanr::package_update(ds, ds_id)
## Replace existing package metadata
# Step 4: illustrate possible or intended data loss - what's not in the dict will be deleted in the package:
del(ds$description)
result_with_deleted_description <- ckanr::package_update(ds, ds_id)
@fernandobarbalho<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ffernandobarbalho&data=02%7C01%7C%7C3276a2ca0f36421a994d08d6c1f6abc1%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636909662513406785&sdata=YBE997kfJq5JhvS5JlRTxwgcoRaNQgDp31vmUVWORtU%3D&reserved=0> if the help for package_update were to include the above clarification and example, would you feel informed enough?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fropensci%2Fckanr%2Fissues%2F108%23issuecomment-483450577&data=02%7C01%7C%7C3276a2ca0f36421a994d08d6c1f6abc1%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636909662513416796&sdata=qUexeavZVYQrdvS5f4xFA7WM%2F8yk8%2BhuE01CVdtv1Og%3D&reserved=0>, or mute the thread<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAmYio6BrHIIxXibXtl4mT_PpzlMoKfJ6ks5vhQVogaJpZM4a-etF&data=02%7C01%7C%7C3276a2ca0f36421a994d08d6c1f6abc1%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636909662513426801&sdata=1TYu%2Bjwq0PE9oDlfqnswNC9%2BP1JzrlCY2BEXRZASI30%3D&reserved=0>.
|
@sckott should I PR an update to the docs for |
@florianm , I am sorry but the code you suggested did not work to me.
when I execute this script bellow...
... the last executed line gives me the following result
which implies that the condition to execute package_update is not correct, as it can be seen when I execute this following script:
|
@florianm , good news so, I suggest to put this in your documentation
|
thanks heaps @fernandobarbalho! |
@florianm yes, please do |
Still in my "later" basket, sorry haven't had bandwidth yet. |
no worries |
This has come up again in the context of updating resources, where everything that isn't specified is deleted. In that function, the documentation explicitly states @florianm, do you expect you'd have bandwidth for updating the docs on this? No worries if not, I can take a go on it. Re-opening this issue to keep my eyes on it 👀 |
Thanks for the reminder, this has been in my "later" basket for too long! Edit: PR sent, apologies haven't been able to run tests locally (no test server creds). @sharlagelfand only if that's appropriate - could you DM me test server credentials on the rOpenSci slack? |
* package_update: Update docs and examples * resource_update: Update docs * DESC: Bump dev version * DESC: Bump RoxygenNote patch version * NEWS: Add mention
Running
package_update()
deletes the resource associated with the package on my CKAN instance, along with some (not all) of the metadata tags for the package that I do not specify.The text was updated successfully, but these errors were encountered: