hydroshare / hsclient

A python client for interacting with HydroShare in an object oriented way.
https://hydroshare.github.io/hsclient/
BSD 3-Clause "New" or "Revised" License
1 stars 4 forks source link

HydroShare.search can cause ResourcePreview: none is not an allowed value (type=type_error.none.not_allowed) #35

Closed aaraney closed 2 years ago

aaraney commented 2 years ago

There are cases where /hsapi/resource/ (the endpoint HydroShare.search wraps) returns an authors field that is either None or [<Author>, None, ...]. The current ResourcePreview handles the case when there are no authors (authors: None), however, it does not handle the case when there is None in a list of authors. See the example below:

from hsclient.json_models import ResourcePreview

ResourcePreview(authors=None)  # ok
ResourcePreview(authors=[])  # ok

ResourcePreview(authors=[None])  # fails
ResourcePreview(authors=["some author", None])  # fails

In a perfect world, the /hsapi/resource/ endpoint would only return a list of valid authors or the empty list, but for now, I think it is acceptable to implement a solution that covers this case and does not cause a parsing exception.

My proposed solution is to filter the list of authors and remove any None authors. Ill open a PR that adds the functionality and ref it here.