Skip to content

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
devin/1773964076-fix-file-id-with-extension
Open

fix: use file existence check instead of extension heuristic in _handle_file_or_url#167
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/1773964076-fix-file-id-with-extension

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

The previous logic in _handle_file_or_url used 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:

  • If the file exists on disk → upload it
  • Otherwise → treat it as a file_id

Also removes the assert not Path(file).suffix guard that prevented file_ids with extensions from being used at all.

Review & Testing Checklist for Human

  • Verify behavior when a Path object points to a non-existent file: Previously this would attempt upload and fail with a clear FileNotFoundError from files.upload(). Now it silently treats it as a file_id, which may produce a confusing API error downstream. Consider whether a Path object (as opposed to a str) should always be treated as a local file and raise early if missing.
  • Test with an actual local file path passed as a string (e.g. file="./my_doc.pdf" where the file exists) to confirm uploads still work correctly.
  • Test with a file_id that contains an extension (e.g. file="document-abc123.pdf") to confirm it's passed through as a file_id without attempting upload.

Notes

  • The else: raise ValueError(...) branch is now only reachable for non-Path, non-str inputs, which matches the type signature Optional[Union[Path, str]].
  • files.upload() already has its own file.exists() check (line 122 in files.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

…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>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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