Skip to content

Commit 4e3dcd0

Browse files
authored
Merge pull request #97 from P2GX/copilot/fix-zenodo-upload-race-condition
Fix Zenodo upload race condition with progressive delays and retry logic
2 parents 33bc42c + cbfdf1b commit 4e3dcd0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

scripts/update_and_release_to_zenodo.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ def delete_existing_files(deposition_id):
8282
requests.delete(delete_url, headers=HEADERS)
8383
print(f"Deleted {file['filename']}")
8484

85+
# Give Zenodo time to process the deletions
86+
if files:
87+
print("Waiting for Zenodo to process deletions...")
88+
time.sleep(3)
89+
8590

8691
def upload_file(deposition_id, file_path, max_retries=5):
8792
"""Uploads a file to the specified deposition with retries."""
@@ -99,9 +104,14 @@ def upload_file(deposition_id, file_path, max_retries=5):
99104
print(f"Uploaded {file_path} successfully.")
100105
return
101106

102-
if response.status_code == 403 and attempt < max_retries - 1:
103-
wait = 2**attempt
104-
print(f"Deposition locked, retrying in {wait}s...")
107+
if response.status_code in (400, 403) and attempt < max_retries - 1:
108+
# For "already exists" errors, use longer waits: 3s, then 30s
109+
if response.status_code == 400:
110+
wait = 3 if attempt == 0 else 30
111+
print(f"File already exists (cache not cleared), retrying in {wait}s...")
112+
else:
113+
wait = 2**attempt
114+
print(f"Deposition locked, retrying in {wait}s...")
105115
time.sleep(wait)
106116
continue
107117

0 commit comments

Comments
 (0)