Skip to content

Commit

Permalink
legacy: fix license parsing to be more flexible
Browse files Browse the repository at this point in the history
* In the legacy deserializer we used to accept license fields as a
  dictionary with a single "id" key.
  • Loading branch information
slint committed Dec 4, 2024
1 parent ea37f28 commit ebd5477
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions site/zenodo_rdm/legacy/deserializers/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,19 @@ def load_rights(self, obj):
if rdm_license:
ret = {"id": rdm_license}
else:
if isinstance(obj, dict) and "id" in obj:
license_id = obj.get("id")
elif isinstance(obj, str):
license_id = obj
else:
raise ValidationError(
f"Invalid license value provided (expected string or object with 'id' key): {obj}"
)

# If license does not exist in RDM, it is added as custom
legacy_license = LEGACY_LICENSES.get(obj)
legacy_license = LEGACY_LICENSES.get(license_id)
if not legacy_license:
raise ValidationError(f"Invalid license provided: {obj}")
raise ValidationError(f"Invalid license provided: {license_id}")
ret = {"title": {"en": legacy_license["title"]}}

return [ret]
Expand Down

0 comments on commit ebd5477

Please sign in to comment.