From d9c8aec8f80d4db673ef25c1023509135e2ae9ed Mon Sep 17 00:00:00 2001 From: Thomas Guillet Date: Mon, 5 Feb 2024 16:55:16 +0100 Subject: [PATCH] Explicit refactor with a comment --- openfisca_core/simulations/simulation.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/openfisca_core/simulations/simulation.py b/openfisca_core/simulations/simulation.py index 2966b9b16..5ea96dd7a 100644 --- a/openfisca_core/simulations/simulation.py +++ b/openfisca_core/simulations/simulation.py @@ -416,12 +416,19 @@ def invalidate_cache_entry(self, variable: str, period): self.invalidated_caches.add(Cache(variable, period)) def invalidate_spiral_variables(self, variable: str): + initial_call_found = False invalidate_entries = False + # 1. find the initial variable call + # 2. find the next variable call + # 3. invalidate all frame items from there for frame in self.tracer.stack: - if invalidate_entries: - self.invalidate_cache_entry(str(frame["name"]), frame["period"]) + if initial_call_found: + if not invalidate_entries and frame["name"] == variable: + invalidate_entries = True + if invalidate_entries: + self.invalidate_cache_entry(str(frame["name"]), frame["period"]) elif frame["name"] == variable: - invalidate_entries = True + initial_call_found = True # ----- Methods to access stored values ----- #