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

Validation error #54

Closed huard closed 1 year ago

huard commented 1 year ago

hs.resource("650ba9303d5942c2b36fa5beafbf612a") fails. Is that an issue with the client or with the metadata ?

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
Cell In[112], line 1
----> 1 hs.resource("650ba9303d5942c2b36fa5beafbf612a")

File /opt/conda/envs/birdy/lib/python3.9/site-packages/hsclient/hydroshare.py:1014, in HydroShare.resource(self, resource_id, validate, use_cache)
   1012 res = Resource("/resource/{}/data/resourcemap.xml".format(resource_id), self._hs_session)
   1013 if validate:
-> 1014     res.metadata
   1016 if use_cache:
   1017     self._resource_object_cache[resource_id] = res

File /opt/conda/envs/birdy/lib/python3.9/site-packages/hsclient/hydroshare.py:216, in Aggregation.metadata(self)
    213 @property
    214 def metadata(self) -> BaseMetadata:
    215     """A metadata object for reading and updating metadata values"""
--> 216     return self._metadata

File /opt/conda/envs/birdy/lib/python3.9/site-packages/hsclient/hydroshare.py:124, in Aggregation._metadata(self)
    121 @property
    122 def _metadata(self):
    123     if not self._retrieved_metadata:
--> 124         self._retrieved_metadata = self._retrieve_and_parse(self.metadata_path)
    125     return self._retrieved_metadata

File /opt/conda/envs/birdy/lib/python3.9/site-packages/hsclient/hydroshare.py:179, in Aggregation._retrieve_and_parse(self, path)
    177 def _retrieve_and_parse(self, path):
    178     file_str = self._hs_session.retrieve_string(path)
--> 179     instance = load_rdf(file_str)
    180     return instance

File /opt/conda/envs/birdy/lib/python3.9/site-packages/hsmodels/schemas/__init__.py:72, in load_rdf(rdf_str, file_format)
     70     return _parse(schema, g)
     71 else:
---> 72     rdf_metadata = _parse(schema, g)
     73     if schema in user_schemas.keys():
     74         return user_schemas[schema](**rdf_metadata.dict())

File /opt/conda/envs/birdy/lib/python3.9/site-packages/hsmodels/schemas/__init__.py:182, in _parse(schema, metadata_graph, subject)
    179 else:
    180     # single
    181     clazz = f.outer_type_
--> 182 parsed_class = _parse(clazz, metadata_graph, value)
    183 if parsed_class:
    184     parsed.append(parsed_class)

File /opt/conda/envs/birdy/lib/python3.9/site-packages/hsmodels/schemas/__init__.py:200, in _parse(schema, metadata_graph, subject)
    198             kwargs[f.name] = parsed[0]
    199 if kwargs:
--> 200     instance = schema(**kwargs, rdf_subject=subject)
    201     return instance
    202 return None

File /opt/conda/envs/birdy/lib/python3.9/site-packages/pydantic/main.py:341, in pydantic.main.BaseModel.__init__()

ValidationError: 1 validation error for DateInRDF
type
  value is not a valid enumeration member; permitted: 'http://purl.org/dc/terms/modified', 'http://purl.org/dc/terms/created', 'http://purl.org/dc/terms/valid', 'http://purl.org/dc/terms/available', 'https://www.hydroshare.org/terms/reviewStarted', 'https://www.hydroshare.org/terms/published' (type=type_error.enum; enum_values=[<DateType.modified: 'http://purl.org/dc/terms/modified'>, <DateType.created: 'http://purl.org/dc/terms/created'>, <DateType.valid: 'http://purl.org/dc/terms/valid'>, <DateType.available: 'http://purl.org/dc/terms/available'>, <DateType.review_started: 'https://www.hydroshare.org/terms/reviewStarted'>, <DateType.published: 'https://www.hydroshare.org/terms/published'>])
sblack-usu commented 1 year ago

Looks like the updated hsmodels requires metadata regeneration within HydroShare. I reproduced this issue and then flipped the dirty metadata flag on this resource. After regenerating the metadata, the client no longer had any issue parsing the metadata files. I'll pass this info along to the developer maintaining HydroShare to regenerate the metadata for other affected resources.

huard commented 1 year ago

Will close this then, thanks.

devincowan commented 1 year ago

@sblack-usu sounds like I need to mark bags dirty for all resources that have review_started or published dates? Neglected after this PR: https://github.com/hydroshare/hsmodels/pull/41