From fc812e24479db35824446f3f3ec9d66fe0f73c39 Mon Sep 17 00:00:00 2001 From: Dinh Long Nguyen Date: Fri, 1 Mar 2024 00:12:34 +0700 Subject: [PATCH] GUI: Fix context reset (#903) --- taipy/gui/utils/_locals_context.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/taipy/gui/utils/_locals_context.py b/taipy/gui/utils/_locals_context.py index 19d00b58d1..bf9c323075 100644 --- a/taipy/gui/utils/_locals_context.py +++ b/taipy/gui/utils/_locals_context.py @@ -48,6 +48,7 @@ def add(self, context: t.Optional[str], locals_dict: t.Optional[t.Dict[str, t.An @contextlib.contextmanager def set_locals_context(self, context: t.Optional[str]) -> t.Iterator[None]: + stack_count = len(self._lc_stack) try: if context in self._locals_map: if hasattr(g, _LocalsContext.__ctx_g_name): @@ -55,7 +56,8 @@ def set_locals_context(self, context: t.Optional[str]) -> t.Iterator[None]: setattr(g, _LocalsContext.__ctx_g_name, context) yield finally: - if hasattr(g, _LocalsContext.__ctx_g_name): + # 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 len(self._lc_stack) > 0: setattr(g, _LocalsContext.__ctx_g_name, self._lc_stack.pop()) else: