ropenscilabs / deposits

R Client for access to multiple data repository services
https://docs.ropensci.org/deposits/
Other
37 stars 3 forks source link

`deposit_update` on frictionless datapackages causes metadata validation issue #104

Closed collinschwantes closed 3 weeks ago

collinschwantes commented 3 weeks ago

I'm trying to update the metadata for a deposit and every method I have tried results in a dcmi term issue

retrieving and updating

   cli <- deposits::depositsClient$new (service = "zenodo", sandbox = TRUE)

  cli$deposit_retrieve(102856)

  cli$deposit_update(path = "outputs/iris_clean/datapackage.json")
## returns: 
  instancePath             schemaPath              keyword additionalProperty
1              #/additionalProperties additionalProperties           metadata
2              #/additionalProperties additionalProperties          resources
                              message
1 must NOT have additional properties
2 must NOT have additional properties
Error: Stopping because the DCMI metadata terms listed above do not conform with the expected schema.

Creating a new client with metadata specified from a file:

   cli2 <- deposits::depositsClient$new (service = "zenodo", sandbox = TRUE,
                               metadata = "outputs/iris_clean/datapackage.json")

## returns: 
  instancePath             schemaPath              keyword additionalProperty
1              #/additionalProperties additionalProperties           metadata
2              #/additionalProperties additionalProperties          resources
[datapackage.json](https://github.com/user-attachments/files/16729334/datapackage.json)

                              message
1 must NOT have additional properties
2 must NOT have additional properties
Error: Stopping because the DCMI metadata terms listed above do not conform with the expected schema.

datapackage.json

mpadge commented 3 weeks ago

@collinschwantes The issue is that the metadata argument currently only allows these two options: https://github.com/ropenscilabs/deposits/blob/aaaf7f7ed3a3f6a587792032bf5ba245b5e3631b/R/client-main.R#L119-L127

Rendered version at https://docs.ropensci.org/deposits/reference/depositsClient.html#method-new-

What i will do in response to this is simply check first if that argument points to a "datapackage.json" file, and extract the metadata only for that.

mpadge commented 3 weeks ago

Hmmm ... No, it's actually already in the code: https://github.com/ropenscilabs/deposits/blob/aaaf7f7ed3a3f6a587792032bf5ba245b5e3631b/R/metadata-validate.R#L242-L247

But a "datapackage.json" file should also have a "profile" field, which yours does not have. I'm not sure what you've done there, but I guess there's no harm simply easing that condition by removing "profile". Next commit will do that.

mpadge commented 3 weeks ago

This code failed before the above commit, but now works:

library (deposits)
packageVersion ("deposits")
#> [1] '0.2.1.60'

url <- "https://github.com/user-attachments/files/16729336/datapackage.json"
destfile <- file.path (tempdir (), basename (url))
chk <- download.file (url = url, destfile = destfile)

cli <- deposits::depositsClient$new (service = "zenodo", sandbox = TRUE, metadata = destfile)
cli
#> <deposits client>
#>  deposits service : zenodo
#>            sandbox: TRUE
#>          url_base : https://sandbox.zenodo.org/api/
#>  Current deposits : <none>
#> 
#>    hostdata : <none>
#>    metadata : 10 terms (see 'metadata' element for details)
#>  local_path : /tmp/RtmpQlQKxv
#>   resources : 1 local, 0 remote

Created on 2024-08-23 with reprex v2.1.1

collinschwantes commented 3 weeks ago

Works for me as well - thanks!