fix: use file existence check instead of extension heuristic in _handle_file_or_url#167
Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Open
Conversation
…le_file_or_url The previous heuristic used file extensions to distinguish between local file paths and file_ids. This broke when a file_id contained an extension (e.g. 'document-abc123.pdf'), causing the SDK to try uploading a non-existent local file. Now the logic is: - If the file exists on disk → upload it - Otherwise → treat as a file_id Co-Authored-By: dylan <dylan@carysoftwaresolutions.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
The previous logic in
_handle_file_or_urlused file extension presence (Path(file).suffix) to decide whether a string was a local file path or a file_id. This broke when a file_id contained an extension (e.g."document-abc123.pdf") — the SDK would attempt to upload a non-existent local file instead of passing it through as a file_id.The new logic checks
file.exists()on disk instead:Also removes the
assert not Path(file).suffixguard that prevented file_ids with extensions from being used at all.Review & Testing Checklist for Human
Pathobject points to a non-existent file: Previously this would attempt upload and fail with a clearFileNotFoundErrorfromfiles.upload(). Now it silently treats it as a file_id, which may produce a confusing API error downstream. Consider whether aPathobject (as opposed to astr) should always be treated as a local file and raise early if missing.file="./my_doc.pdf"where the file exists) to confirm uploads still work correctly.file="document-abc123.pdf") to confirm it's passed through as a file_id without attempting upload.Notes
else: raise ValueError(...)branch is now only reachable for non-Path, non-strinputs, which matches the type signatureOptional[Union[Path, str]].files.upload()already has its ownfile.exists()check (line 122 infiles.py), so the double-check is redundant for the upload path but harmless.Link to Devin session: https://app.devin.ai/sessions/691f8a989ec340a397e56a2e178b91d7
Requested by: @DylanSoftware