Search cache: preserve falsy provider returns to match original behavior
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.
This commit is contained in:
parent
fd7b56e58c
commit
47b4663091
2 changed files with 15 additions and 3 deletions
|
|
@ -78,17 +78,17 @@ def get_cache_key(
|
||||||
normalized_query = (query or '').strip().lower()
|
normalized_query = (query or '').strip().lower()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
active_server = active_server_provider() or 'unknown'
|
active_server = active_server_provider()
|
||||||
except Exception:
|
except Exception:
|
||||||
active_server = 'unknown'
|
active_server = 'unknown'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fallback_source = fallback_source_provider() or 'unknown'
|
fallback_source = fallback_source_provider()
|
||||||
except Exception:
|
except Exception:
|
||||||
fallback_source = 'unknown'
|
fallback_source = 'unknown'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hydrabase_active = bool(hydrabase_active_provider())
|
hydrabase_active = hydrabase_active_provider()
|
||||||
except Exception:
|
except Exception:
|
||||||
hydrabase_active = False
|
hydrabase_active = False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,3 +119,15 @@ def test_key_hydrabase_provider_failure_falls_back_to_false():
|
||||||
fallback_source_provider=lambda: 'spotify',
|
fallback_source_provider=lambda: 'spotify',
|
||||||
hydrabase_active_provider=boom)
|
hydrabase_active_provider=boom)
|
||||||
assert key[3] is False
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue