From c856baf7efc9a986da5b4ad2d497a1741819c55f Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Sun, 23 Aug 2026 14:28:09 -0400 Subject: [PATCH] fix(memory): file the cache-hit result before running its callback Restores the original ordering. Releasing the payload after the callback meant filing the result after it too, so a callback that queried get_result() or is_request_complete() for its own request would not have found it -- a behaviour change unrelated to the memory fix. The dict holds a reference to the same object, so releasing after filing still clears the payload. Co-Authored-By: Claude Opus 5 --- src/background_data_service.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/background_data_service.py b/src/background_data_service.py index 1011a1f0..99e101a4 100644 --- a/src/background_data_service.py +++ b/src/background_data_service.py @@ -199,6 +199,12 @@ class BackgroundDataService: cached=True, fetch_time=0.0 ) + # Filed before the callback runs, as it always was: a callback + # that queries get_result()/is_request_complete() for its own + # request must still find it. Releasing afterwards mutates the + # same object the dict holds. + self.completed_requests[request_id] = result + if callback: try: callback(result) @@ -206,8 +212,6 @@ class BackgroundDataService: logger.error(f"Error in callback for request {request_id}: {e}") self._release_payload(result) - self.completed_requests[request_id] = result - logger.debug(f"Cache hit for {sport} {year} data") return request_id