Fix file/PDF add crash on a null-stat source row#418
Merged
Conversation
Adding any file failed with 'int() argument ... not NoneType' when the store held a source row whose nullable stat columns (size_bytes / mtime_ns / stat_captured_ns) were NULL. source_stat only guarded the SOURCE_STAT_UNKNOWN sentinel and missing keys via .get-default, so an explicit NULL slipped through to int(None). Treat NULL like unknown (return None, the caller re-hashes) and coerce a NULL capture time to the sentinel instead of crashing. Bug present since the stat-based sync-skip landed in #338; surfaces on any store carrying a null-stat row.
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
Adding any file (the user hit it on PDFs) fails immediately with
int() argument must be a string, a bytes-like object or a real number, not 'NoneType'when the knowledge base already holds a source row whose stat columns are NULL.source_stat()reads a row'ssize_bytes/mtime_ns/stat_captured_nsto decide whether a file can skip re-hashing. Those columns are nullableint64, but the reader only handled two "unknown" cases: a missing key (via.get(key, SOURCE_STAT_UNKNOWN)) and the-1sentinel. An explicit NULL is neither, so it slipped past the guard intoint(None)and crashed. The capture-time column wasn't checked at all, so a NULL there crashed even with valid size/mtime.Solution
Treat a NULL stat column the same as unknown: return
Noneso the caller re-hashes the file (the documented "no usable stat" path), and coerce a NULL capture time to the sentinel instead of callingint()on it. No behavior change for rows that already carry real stats or the sentinel.Reproduced with two regression tests (NULL size/mtime, and NULL capture time alongside valid size/mtime) that fail with the exact error before the fix.