cthoyt / zenodo-client

A tool for automated uploading and version management of scientific data to Zenodo
MIT License
25 stars 5 forks source link

`create()` doesn't check types of arguments, can result in errors #33

Closed rhigman closed 5 months ago

rhigman commented 7 months ago

If data argument is present but not valid (e.g. wrong type), create() proceeds with the deposit attempt anyway, triggering an error response from Zenodo. This error response is printed to the command line, and includes the submitted access token.

>>> zenodo.create(data=None, paths=['/valid/file/path'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rh/.local/lib/python3.10/site-packages/zenodo_client/api.py", line 126, in create
    res.raise_for_status()
  File "/home/rh/.local/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: INTERNAL SERVER ERROR for url: https://sandbox.zenodo.org/api/deposit/depositions?access_token=REDACTED

If paths argument is present but not valid (e.g. empty), a similar result occurs.

>>> zenodo.create(data=valid_metadata_object, paths=[])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rh/.local/lib/python3.10/site-packages/zenodo_client/api.py", line 138, in create
    return self.publish(deposition_id)
  File "/home/rh/.local/lib/python3.10/site-packages/zenodo_client/api.py", line 154, in publish
    res.raise_for_status()
  File "/home/rh/.local/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: BAD REQUEST for url: https://sandbox.zenodo.org/api/deposit/depositions/32867/actions/publish?access_token=REDACTED

I'm on tag 0.3.2, but I think the issue is still present in main.

cthoyt commented 5 months ago

The first case can be caught with static type checking - it's written in the documentation that data should not be none. Paths being empty is also something that you should take care of yourself - as of #28 it's also possible to add an empty set of paths in case you aren't planning on uploading any files and just creating some metadata.