fix(cache): give each cache instance its own dict - #233
Open
JediBrooker wants to merge 1 commit into
Open
JediBrooker wants to merge 1 commit into
JediBrooker wants to merge 1 commit into
Conversation
`_cache` was declared as a class attribute on both SimpleCache and StringConfigCache, so every instance in the app shared one dict. For StringConfigCache this only meant the configs shared storage, since their keys do not overlap. For SimpleCache it is a bug: both prowlarr_source_cache and prowlarr_indexer_cache key off a single string, so cached search results land in the same keyspace as cached indexers. Once any book has been searched for, get_indexers() reads those search results back out of prowlarr_indexer_cache and Settings>Indexers fails with "'list' object has no attribute 'id'". Moving the dict into __init__ keeps the instances independent. flush() already rebound self._cache, so it was silently creating an instance attribute and diverging from the shared one anyway.
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.
What
_cachewas declared as a class attribute on bothSimpleCacheandStringConfigCache, so every instance in the app shared a single dict.For
StringConfigCachethis is harmless today — the config classes have disjoint key literals, so they were only sharing storage.For
SimpleCacheit's a bug.prowlarr_source_cacheandprowlarr_indexer_cacheboth key off a single string, so cached search results land in the same keyspace as cached indexers.get_indexers()then reads those search results back out:indexeris alist[ProwlarrSource], and the whole thing lands in theexcept Exceptioninget_indexers.Reproducing
Search for any book, then open
Settings > Indexers. It renders the error state with:Minimal version:
It's intermittent in practice, which is probably why it hasn't been pinned down: it only shows up once something has been cached, and
flush_prowlarr_cache()(called when the Prowlarr settings are saved) happens to paper over it —flush()doesself._cache = {}, which creates an instance attribute and silently diverges from the shared class one from then on. So the fix also makesflush()mean what it looks like it means.The change
Moves both dicts into
__init__. Six lines, no behaviour change beyond the instances no longer colliding.Checked
uv run basedpyright— cleanuv run ruff format --check app— cleanuv run alembic checkon a fresh DB — no new operations (no schema change here)SimpleCache/StringConfigCachesubclass is instantiated exactly once as a module-level singleton, so nothing depended on the sharingAuthConfig,oidcConfig,ProwlarrConfig,ABSConfigand the quality/indexer configs, so no config loses a value it was previously reading out of a sibling's cacheWritten with AI assistance; the diagnosis and the reproduction above were verified by hand against
main.