Fix extension-less filenames never getting a .txt default - #1576
Open
Osamaali313 wants to merge 1 commit into
Open
Osamaali313 wants to merge 1 commit into
Osamaali313 wants to merge 1 commit into
Conversation
`ResourceHelper.make_written_file_resource` tries to append a `.txt`
extension when the written file has none:
file_parts = os.path.splitext(file_name)
if len(file_parts) <= 1:
file_name = file_name + ".txt"
But `os.path.splitext()` always returns a 2-tuple `(root, ext)`, so
`len(file_parts)` is always 2 and the guard is never true — the `.txt`
default is dead code. The very next line reads the extension from
`os.path.splitext(file_name)[1]`, which shows the extension lives in the
tuple's `[1]` slot, not in its length.
As a result, an agent writing an extension-less file (e.g. `report`) is
stored with no extension and its `file_type` falls through to
`application/misc` instead of `application/txt`.
Check the extension component instead of the tuple length.
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.
Problem
ResourceHelper.make_written_file_resource(superagi/helper/resource_helper.py) tries to give a.txtextension to a written file that has none:os.path.splitext()always returns a 2-tuple(root, ext), solen(file_parts)is always2andlen(file_parts) <= 1is never true. The.txtdefault is dead code.The intent is clearly "if the filename has no extension, append
.txt" — and the very next line reads the extension fromos.path.splitext(file_name)[1], confirming the extension lives in the tuple's[1]slot, not in its length.Impact
An agent writing an extension-less file (e.g.
report) is stored with no.txtsuffix, and itsfile_typeclassification falls through toapplication/miscinstead ofapplication/txt.make_written_file_resourceis the write path used byresource_manager/file_manager.py(write_to_s3viawrite_file/write_binary_file/write_csv_file).Reproduction
len(file_parts) <= 1)reportapplication/misc❌not file_parts[1])report.txtapplication/txt✅Fix