Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upload-files): close file handle before handling error (DEV-2666) #519

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 10 additions & 15 deletions src/dsp_tools/fast_xmlupload/upload_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,21 @@ def _upload_without_processing(
"""
try:
with open(file, "rb") as bitstream:
try:
response_upload = requests.post(
url=f"{regex.sub(r'/$', '', sipi_url)}/upload_without_processing",
headers={"Authorization": f"Bearer {con.get_token()}"},
files={"file": bitstream},
timeout=8 * 60,
)
except Exception: # pylint: disable=broad-exception-caught
return _call_upload_without_processing_recursively(
file=file,
sipi_url=sipi_url,
con=con,
err_msg=f"The /upload_without_processing route raised an exception for {file}. Retrying...",
)
response_upload = requests.post(
url=f"{regex.sub(r'/$', '', sipi_url)}/upload_without_processing",
headers={"Authorization": f"Bearer {con.get_token()}"},
files={"file": bitstream},
timeout=8 * 60,
)
except Exception: # pylint: disable=broad-exception-caught
return _call_upload_without_processing_recursively(
file=file,
sipi_url=sipi_url,
con=con,
err_msg=f"Opening the file {file} raised an exception. Retrying...",
err_msg=(
f"An exception occurred while opening the file {file} "
"or while sending it to the /upload_without_processing route. Retrying..."
),
)

if response_upload.json().get("message") == "server.fs.mkdir() failed: File exists":
Expand Down