Skip to content

Commit

Permalink
GUI: Fix context reset (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhlongviolin1 authored Feb 29, 2024
1 parent 5584560 commit fc812e2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion taipy/gui/utils/_locals_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ 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):
self._lc_stack.append(getattr(g, _LocalsContext.__ctx_g_name))
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:
Expand Down

0 comments on commit fc812e2

Please sign in to comment.