Conversation
url_to_stream returned the response body without checking the status, so a 404 page was uploaded to the API as if it were the file. Error statuses now raise APIStatusError, and transport failures raise APIConnectionError / APITimeoutError, matching how the rest of the SDK reports failures. The download also gets an explicit timeout. Fixes deepinfra#22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #22.
Problem
ReadStreamUtils.url_to_streamreturned the response body without checking the status:A blob field given as a URL is fetched through this path by
FormDataUtils.get_form_data, so when the URL 404s the error page's bytes are uploaded as the file:The user then gets a model-side error with nothing pointing at the dead URL. It is the only place in the SDK where a failed HTTP response is neither raised nor surfaced: the client maps every error status onto
APIStatusError, and a wrong local path already raisesFileNotFoundError.Changes
url_to_streamraisesAPIStatusError(with the status code and the response) when the download answers with an error status, andAPIConnectionError/APITimeoutErroron transport failures, matching_map_transport_errorin the client.tests/test_read_stream.pycovers the success path, 404/401/500, connect errors, timeouts, propagation throughFormDataUtils.get_form_data, and that bytes,data:URIs and missing local files are unaffected.Without the change, 6 of the 9 new tests fail.
Verification
Python 3.12, from a clean install of
.[dev]:Not included
The issue mentions three smaller points in the same file (a local path beginning with
httpbeing treated as a URL, adata:URI without a comma raisingIndexError, andBaseModel._warn_about_missing_api_keysending an empty bearer token instead of raisingAuthenticationError). They are left out to keep this focused, and I'm happy to send them separately if you want them.