mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
fix(cache): leave no empty cache file after a failed cached call
cache_in_file created the cache file before it called the function. When the call raised, e.g. a provider request answered with HTTP 500, the empty file stayed in the store until it expired, and the next call logged "Read failed: Ran out of input" before it called the function again. The function is now called first; a failed call leaves the store unchanged. Refs #1571 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
committed by
Bobby Noelte
co-authored by
Claude Opus 5.5
parent
c8f793c203
commit
14acf759a7
@@ -904,6 +904,27 @@ class TestCacheFileDecorators:
|
||||
assert f() == "result"
|
||||
assert len(calls) == 2
|
||||
|
||||
def test_failed_call_leaves_no_cache_file(self, cache_file_store, caplog) -> None:
|
||||
"""A call that raises caches nothing, so the next call reads no empty file (#1571)."""
|
||||
cache_file_store.clear(clear_all=True)
|
||||
responses: list[Exception | str] = [RuntimeError("500 Server Error"), "result"]
|
||||
|
||||
@cache_in_file(with_ttl="1 hour")
|
||||
def fetch() -> str:
|
||||
response = responses.pop(0)
|
||||
if isinstance(response, Exception):
|
||||
raise response
|
||||
return response
|
||||
|
||||
with pytest.raises(RuntimeError, match="500 Server Error"):
|
||||
fetch()
|
||||
assert len(cache_file_store._store) == 0
|
||||
|
||||
assert fetch() == "result"
|
||||
assert "Read failed" not in caplog.text
|
||||
assert fetch() == "result"
|
||||
assert responses == []
|
||||
|
||||
def test_var_positional_arguments_are_part_of_the_key(self, cache_file_store):
|
||||
cache_file_store.clear(clear_all=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user