Repository navigation
fix(caching): skip materialized payloads in FileResultStore.delete_expired - #1834
Open
getBrijendra wants to merge 1 commit into
Open
getBrijendra wants to merge 1 commit into
getBrijendra wants to merge 1 commit into
Conversation
…pired `FileResultStore.set()` with a saver/loader writes a pickled loader at `<data_version>` and the payload at `<data_version>.<saver name>` in the same directory. `delete_expired()` iterated every entry and unpickled it, so a JSON (or any non-pickle) payload raised `UnpicklingError`. Only treat suffix-less files as result entries, and skip entries that can't be unpickled instead of crashing cleanup. Closes apache#1813 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
I saw @ashutosh8021 offered to take this on in #1813. I ran into it while exploring the caching code and put this up in case it helps. Happy to close this in favour of their PR, or add them as co-author, whichever the maintainers and @ashutosh8021 prefer. |
This was referenced Nov 28, 2026
This branch has not been deployed
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.
Fixes
FileResultStore.delete_expired()crashing withUnpicklingErrorwhen the store contains results saved with a saver/loader (e.g., the built-in JSON saver).Closes #1813
Changes
FileResultStore.set()with a saver/loader writes two files into the store directory: a pickled loader at<data_version>and the materialized payload at<data_version>.<saver name>(via_materialized_path).delete_expired()iterated every directory entry and passed it toStoredResult.load(), so the payload (e.g.,example.json) was unpickled and raised.hamilton/caching/stores/file.py_is_result_entry(): result entries are regular files with no suffix; materialized payloads always have a suffix, and some savers write directories.delete_expired()skips non-result entries, and skips entries that fail to unpickle (UnpicklingError/EOFError) instead of aborting cleanup.tests/caching/result_store/test_file.pytest_delete_expired_skips_materialized_payloads(json + pickle): cleanup succeeds, both files remain, values stay readable.test_delete_expired_ignores_unreadable_entries: a non-pickle file, an empty file and a suffixed directory don't break cleanup.How I tested this
UnpicklingErrorbefore the change, passes after.UnpicklingError,EOFError); all pass with it. (The pickle-format case passes either way since that payload is valid pickle; it's kept for coverage.)pytest tests/caching/result_store tests/caching/test_result_store.py: 33 passed.pytest tests/ --ignore tests/integrationson Windows / Python 3.12: 1721 passed, 12 failed. The failures are unrelated to this change and environment-specific: Graphvizdotnot installed (6),MultiProcessingExecutorBrokenProcessPoolon Windows (3),<unhashable>being an invalid Windows filename (1), and cp1252 decoding /h_asyncsubprocess intest_deprecation_schedules.py(2). I confirmed the caching-integration failures also occur without this change.ruff check/ruff format --check(0.16.9) clean on the changed files.Notes
Kept deliberately narrow, per the issue. Related problems noticed while investigating, which could be follow-ups:
StoredResult.save()doesn't persistexpires_atandStoredResult.load()rebuilds with no expiry, sodelete_expired()currently never removes anything.delete_expired()loads every value (running loaders) just to check expiry.delete()/ expiry remove only the pointer file, leaving the materialized payload behind.Checklist
🤖 Generated with Claude Code