Selaa lähdekoodia

Fix: Enhance Context Reset (#903) (#905)

Dinh Long Nguyen 1 vuosi sitten
vanhempi
säilyke
e024c8fa47
1 muutettua tiedostoa jossa 3 lisäystä ja 3 poistoa
  1. 3 3
      taipy/gui/utils/_locals_context.py

+ 3 - 3
taipy/gui/utils/_locals_context.py

@@ -48,16 +48,16 @@ class _LocalsContext:
 
     @contextlib.contextmanager
     def set_locals_context(self, context: t.Optional[str]) -> t.Iterator[None]:
-        stack_count = len(self._lc_stack)
+        has_set_context = False
         try:
             if context in self._locals_map:
                 if hasattr(g, _LocalsContext.__ctx_g_name):
                     self._lc_stack.append(getattr(g, _LocalsContext.__ctx_g_name))
                 setattr(g, _LocalsContext.__ctx_g_name, context)
+                has_set_context = True
             yield
         finally:
-            # Only reset the stack if `stack_count` has been changed, meaning the context has been set above in the try statement
-            if hasattr(g, _LocalsContext.__ctx_g_name) and stack_count == (len(self._lc_stack) - 1):
+            if has_set_context and hasattr(g, _LocalsContext.__ctx_g_name):
                 if len(self._lc_stack) > 0:
                     setattr(g, _LocalsContext.__ctx_g_name, self._lc_stack.pop())
                 else: