fix(cli): read OpenAI FileObject via attribute access, not subscript - #2441
Closed
chuenchen309 wants to merge 1 commit into
Closed
fix(cli): read OpenAI FileObject via attribute access, not subscript#2441chuenchen309 wants to merge 1 commit into
chuenchen309 wants to merge 1 commit into
Conversation
openai.types.FileObject is a Pydantic model, not a dict/TypedDict — it is not subscriptable. generate_file_table() (used by `instructor files list`) and upload() (used by `instructor files upload`) both indexed it with file["id"]-style access, so every call to either command raised TypeError: 'FileObject' object is not subscriptable. The sibling instructor/cli/jobs.py already reads the analogous OpenAI SDK object via attribute access, confirming files.py was the outlier. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
|
Consolidated and shipped in #2495. Closing this focused patch as superseded; thank you for the contribution. |
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.
Describe your changes
openai.types.FileObjectis a Pydantic model, not a dict/TypedDict— it isn't subscriptable.generate_file_table()(backinginstructor files list) andupload()(backinginstructor files upload) both read it withfile["id"]-style indexing, so every invocation of either command crashes:The sibling
instructor/cli/jobs.py'sgenerate_table()already reads the analogous OpenAI SDK object via attribute access (job.id,job.status, ...), confirmingfiles.pyis the outlier, not an intentional pattern.Fix:
file["id"]→file.id(andbytes/created_at/filename/purpose) ingenerate_file_table, andresponse["id"]→response.idinupload()(same bug,client.files.create()also returns aFileObject).Issue ticket number and link
None found — searched open PRs/issues touching
cli/files.py, no overlap.Checklist before requesting a review
Testing
tests/cli/test_files.py::test_generate_file_table_uses_attribute_access; confirmed (viagit stash) it fails with the exactTypeErroragainst the pre-fix code, passes after.ruff check,ruff format --check,ty checkall clean on the changed files.CHANGELOG.mdentry under[Unreleased] / FixedperCLAUDE.md's PR guidelines.AI disclosure
Developed with AI assistance (Claude Code), which located the crash via a search across
instructor/cli/for functions untouched by any test, and noticed both call sites shared the same root cause. I reviewed the diff, independently confirmed the fix against the siblingjobs.pypattern, and ran the test/lint/type checks myself before opening this PR.