From 47b4663091f60fa509e8cbc7078014c9c1ca35c9 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:19:52 -0700 Subject: [PATCH] Search cache: preserve falsy provider returns to match original behavior MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Line-by-line review of the search lift caught one drift: cache.get_cache_key was coercing falsy provider returns ('', None, 0) to 'unknown' / False. Original web_server.py only fell back to those sentinels on exception, not on falsy success values. Real-world impact: low — get_active_media_server() and get_primary_source() return non-empty strings in practice. But cache keys are tuples with no schema enforcement, so any drift here can silently fragment the cache. Restored 1:1 parity with original semantics. Added test covering the falsy-success path so this can't drift again. 789 tests pass, ruff clean. --- core/search/cache.py | 6 +++--- tests/search/test_search_cache.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/search/cache.py b/core/search/cache.py index 4692f3dd..e988c04d 100644 --- a/core/search/cache.py +++ b/core/search/cache.py @@ -78,17 +78,17 @@ def get_cache_key( normalized_query = (query or '').strip().lower() try: - active_server = active_server_provider() or 'unknown' + active_server = active_server_provider() except Exception: active_server = 'unknown' try: - fallback_source = fallback_source_provider() or 'unknown' + fallback_source = fallback_source_provider() except Exception: fallback_source = 'unknown' try: - hydrabase_active = bool(hydrabase_active_provider()) + hydrabase_active = hydrabase_active_provider() except Exception: hydrabase_active = False diff --git a/tests/search/test_search_cache.py b/tests/search/test_search_cache.py index 15ae6517..eb4a67d8 100644 --- a/tests/search/test_search_cache.py +++ b/tests/search/test_search_cache.py @@ -119,3 +119,15 @@ def test_key_hydrabase_provider_failure_falls_back_to_false(): fallback_source_provider=lambda: 'spotify', hydrabase_active_provider=boom) assert key[3] is False + + +def test_key_preserves_falsy_provider_returns(): + """Original behavior: if provider returns None / '' on success, store it + as-is. Don't coerce to 'unknown' — that's reserved for exceptions.""" + key = search_cache.get_cache_key('q', None, + active_server_provider=lambda: None, + fallback_source_provider=lambda: '', + hydrabase_active_provider=lambda: 0) + assert key[1] is None + assert key[2] == '' + assert key[3] == 0