caltechlibrary / caltechdata_api

Python library for using the CaltechDATA API
Other
10 stars 2 forks source link

edit entry with new files #20

Closed caseyjlaw closed 1 year ago

caseyjlaw commented 1 year ago

I'm trying to update/edit an entry by adding a file. The entry is published at https://data.caltech.edu/records/3c8kh-x6373. If I use caltechdata_edit function with a known idv, metadata, and new version number, then it can update the version number. However, if I pass in an argument to files, then it triggers an exception:

  File "/home/ubuntu/anaconda3/envs/casa38/lib/python3.8/site-packages/caltechdata_api/caltechdata_edit.py", line 151, in caltechdata_edit
    raise Exception(result.text)
Exception: {"status": 404, "message": "Not found."}

That exception comes in this logic in caltechdata_edit.py (starting at line 144):

    if version:
        # We need to make new version                                                                                                               
        result = requests.post(
            url + "/api/records/" + idv + "/versions",
            headers=headers,
        )
        if result.status_code != 201:
            raise Exception(result.text)
        # Get the id of the new version                                                                                                             
    idv = result.json()["id"]

If I change the POST to a GET, then I get a result with code=200 and an "id" field. Did the API change to use a different method and status value?

tmorrell commented 1 year ago

I haven't been able to reproduce that error on that record or on records on our test system or on other DSA-110 records. We do have an intermittent system bug that can prevent versions from being created, and I suspect that's what you ran into. If it occurs let me know as I can reset the versions on the back end.

The other think you'll have to do with your versions is to create a new 10.25800 DOI for the version, and pass that along with the metadata, otherwise you'll automatically get a system DOI assigned. Let me know if you need to edit files on a record without creating a version. I can do that administratively, though we don't have a good way for not-admin users to do that yet.

I also released version 1.4.4 of caltechdata_api, which fixed some other bugs that I found during testing but which probably don't impact your use case.

caseyjlaw commented 1 year ago

I am also no longer seeing that error. I am seeing an error saying I need a new DOI, though, so that's consistent with what you are saying. I was able to change the version number before without changing the DOI. What triggers the requirement for a new DOI? In what scenarios would increment versions rather than create a new entry/DOI?

tmorrell commented 1 year ago

A new version is used when you're making significant changes to the files. CaltechDATA locks the files once the record is published, and the only way for users to edit the files at the moment is to create a new version. As an administrator I can change the files without creating a version, which we usually use when files were uploaded by mistake or the user wants to add new files. Any time a new version is created it needs a new DOI.

The version number in the metadata can be changed at any time. A future use case for changing the version number without creating a version is if you were adding processed data files after publishing the initial record. But at the moment it's not possible for users to do this.

caseyjlaw commented 1 year ago

Ok, thanks. This latter scenario is what I imagined, but I have no problem creating a new DOI for a new version.