Skip to content

Commit

Permalink
files: fix pending files keyError in legacyjson
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatimah authored and slint committed Feb 1, 2024
1 parent 0965588 commit 87d1517
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions site/zenodo_rdm/legacy/serializers/schemas/legacyjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,24 @@ def dump_files(self, obj):
result = []
files_url = obj["links"].get("files")
for key, f in obj["files"].get("entries", {}).items():
file_id = f["id"]
if files_url:
file_id = f.get("id")
if (
file_id is not None
): # Check if 'id' is present in case of pending/failed file upload
links = {"self": f"{files_url}/{file_id}"}
links["download"] = (
f"{current_app.config['SITE_API_URL']}/records/{obj['id']}/draft/files/{key}/content"
)
result.append(
{
"id": f["id"],
"filename": f["key"],
"filesize": f["size"],
# skip the checksum algorithm prefix
"checksum": f["checksum"].split(":", 1)[1],
"links": links,
}
)
result.append(
{
"id": file_id,
"filename": f["key"],
"filesize": f["size"],
# skip the checksum algorithm prefix
"checksum": f["checksum"].split(":", 1)[1],
"links": links,
}
)
return result

@pre_dump
Expand Down

0 comments on commit 87d1517

Please sign in to comment.