Not having ID break index cache key across Python invocations#1262
Merged
jamesbraza merged 3 commits intomainfrom Jan 5, 2026
Merged
Not having ID break index cache key across Python invocations#1262jamesbraza merged 3 commits intomainfrom
jamesbraza merged 3 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes cache key instability caused by function memory addresses appearing in string representations across Python invocations. The fix introduces a new utility function get_stable_str() that generates stable string representations for functions, handling special cases like lambdas and functools.partial objects.
Key changes:
- Added
get_stable_str()utility function to generate stable function identifiers using fully qualified names (FQN) for normal functions and code hashes for lambdas/partials - Updated
ParsingSettings._custom_serializer()to useget_stable_str()for JSON-safe serialization - Modified
Settings.get_index_name()to useget_stable_str()for stable cache key generation - Added test cases for lambda and partial function handling
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/paperqa/utils.py | Added get_stable_str() function to generate stable string representations for functions, avoiding memory address issues in cache keys |
| src/paperqa/settings.py | Updated serialization and index name generation to use get_stable_str() instead of direct string conversion |
| tests/test_paperqa.py | Added test stubs and test cases to verify lambda and partial functions don't break serialization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… Python invocations
52d4a3f to
f0f3f37
Compare
sidnarayanan
approved these changes
Jan 5, 2026
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.
#1125 differentiated cache keys across PDF parse functions, but inadvertently exposed us to this:
Namely, the ID shown in the
strrepresentation is breaking the cache key across Python invocations 🫠. This PR:lambdaandfunctools.partialCloses #1257