Skip to content

Fix file transfers ignoring connection 'max_retries' - #358

Draft
BigRoy wants to merge 1 commit into
developfrom
bugfix/transfer-max-retries
Draft

Fix file transfers ignoring connection 'max_retries'#358
BigRoy wants to merge 1 commit into
developfrom
bugfix/transfer-max-retries

Conversation

@BigRoy

@BigRoy BigRoy commented Sep 12, 2026

Copy link
Copy Markdown
Member

Bug

File uploads and downloads ignore the connection's max_retries and can end up making zero attempts:

  • con.set_max_retries(1) (or ServerAPI(..., max_retries=1)) has no effect on transfers; they always use the env variable / class default (3).
  • With AYON_SERVER_RETRIES=0:
    • uploads crash: AttributeError: 'NoneType' object has no attribute 'raise_for_status'
    • downloads silently do nothing — no request, no error, empty/missing file.

Cause

_upload_file and _download_file_to_stream used self.get_default_max_retries() instead of self.max_retries, and looped for attempt in range(retries) without ensuring at least one attempt. REST requests (_do_rest_request) already clamp to at least 1.

Fix

Use max(self.max_retries, 1) in both transfer functions.

Reproduce

AYON_SERVER_RETRIES=0 python -c "
import ayon_api
con = ayon_api.get_server_api_connection()
print(con.create_thumbnail('<project>', '/path/to/image.png'))
"
# develop: AttributeError: 'NoneType' object has no attribute 'raise_for_status'
# this PR: <thumbnail id>

Download with zero retries:

import io, ayon_api
con = ayon_api.get_server_api_connection()  # with AYON_SERVER_RETRIES=0
stream = io.BytesIO()
con.download_file_to_stream(f"api/projects/<project>/thumbnails/<thumbnail id>", stream)
print(len(stream.getvalue()))  # develop: 0

Testing notes

  • tests/test_transfer_max_retries.py: zero retries still uploads/downloads; max_retries=1 makes exactly one upload attempt.

Stacked PRs touching the same download/upload loop build on top of this branch.

🤖 Generated with Claude Code

Uploads and downloads used 'get_default_max_retries()' (env variable or
class default) instead of the connection's 'max_retries', and did not
ensure at least one attempt. With 'AYON_SERVER_RETRIES=0' an upload
crashed with AttributeError on 'None' response and a download silently
did not download anything.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant