fix: add early returns for md/json/xml/yaml in guess_file_type#3090
Open
totto wants to merge 1 commit into
Open
fix: add early returns for md/json/xml/yaml in guess_file_type#3090totto wants to merge 1 commit into
totto wants to merge 1 commit into
Conversation
…type filetype.guess() relies on magic bytes and returns None for text-based formats (.md, .json, .xml, .yaml/.yml). Without extension-based early returns these all fell through to the None fallback and were labeled text/plain, discarding the actual format. Also remove unreachable dead code: the second `if file_type is None` check after an unconditional assignment can never be True. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Bug
guess_file_typereturnstext/plainfor.md,.json,.xml,.yaml, and.ymlfiles instead of their correct MIME types.Root cause
filetype.guess()uses magic-byte signatures and returnsNonefor text-based formats that have no binary header. The function already handled.txt,.text, and.csvwith extension-based early returns, but left the rest to fall through:This means a JSON file ingested by cognee is tagged as
text/plainwith extensiontxt, which breaks downstream pipeline steps that branch on MIME type.A secondary dead-code issue: after the unconditional assignment above, the following check can never be True and was removed:
Fix
Add extension-based early returns for the missing text formats, consistent with the existing
.txt/.csvpattern:.md,.markdowntext/markdown.jsonapplication/json.xmlapplication/xml.yaml,.ymlapplication/yamlRemove the unreachable
raise FileTypeExceptionbranch.🤖 Generated with Claude Code