Repository navigation
Conversation
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.
Description
On Windows,
SimpleDirectoryReader.load_data()failed withOSError: [Errno 22] Invalid argumentwhen any file had a modification time before 1970, becausedatetime.fromtimestamp()does not accept negative timestamps there. The metadata is built outside theraise_on_errortryblock, so a single file made the whole call fail._format_file_timestamp()now catchesOSError,OverflowErrorandValueErrorand returnsNone. This follows the function's existing contract (it already returnsNonefor a missing timestamp), anddefault_file_metadata_func()already dropsNonevalues, so only that date field is omitted and the file still loads. Other behavior is unchanged.Fixes #23787
New Package?
Version Bump?
Type of Change
How Has This Been Tested?
I added new unit tests to cover this change
test__format_file_timestamp_out_of_range:inf,1e20andnanreturnNoneinstead of raising. These values fail on every OS, so this test catches the bug on Linux CI too.test_SimpleDirectoryReader_pre_epoch_mtime: loads a real file whose mtime is set to 1969-12-31 and checks that the text andfile_namemetadata are kept. Before the fix it failed withOSErroron Windows.I confirmed that both new tests fail without the fix and pass with it.
uv run -- pytest tests/readers/passes (33 passed) on Windows 11 / Python 3.11.15, andpre-commitpasses on the changed files.AI Usage
I used Claude (an AI assistant) to help find this edge case, draft the fix and tests, and polish the English in this description. I reproduced the bug myself on Windows, checked for existing issues/PRs, reviewed every changed line, and ran the tests locally before and after the fix.
Suggested Checklist:
uv run make format; uv run make lintto appease the lint gods