`Gui.__exit__` Unconditionally Returns `True`, Illegitimately Swallowing All Exceptions in `with state:` and `with gui:`
Author: codeCraft-RitikCreated Sep 22, 2026Updated Sep 22, 2026
Bug : Gui.__exit__ Unconditionally Returns True, Illegitimately Swallowing All Exceptions in with state: and with gui:
1. File & Lines
- File:
taipy/gui/gui.py&taipy/gui/state.py - Lines: 1554–1562
- Method:
Gui.__exit__(self, exc_type, exc_value, traceback)
2. Description & Real-World Impact
Taipy's official guide instructs developers to use with state: to batch variable modifications and send a single bulk update over WebSockets:
with state:
state.var_a = 1
state.var_b = 2In Gui.__exit__:
def __exit__(self, exc_type, exc_value, traceback):
try:
self.__send_messages()
except Exception as e: # pragma: no cover
_warn("Exception raised while sending messages", e)
if exc_value: # pragma: no cover
_warn(f"An {exc_type or 'Exception'} was raised", exc_value)
return TrueUnder Python PEP 343 (The "with" Statement):
"If
__exit__returns a true value, the exception is suppressed. If it returns false or None, the exception is re-raised."
Because Gui.__exit__ always returns True, any and all exceptions occurring inside a with state: or with gui: block are completely swallowed!
- If a critical database query, calculation, or network call inside
with state:fails withRuntimeError,KeyError,ValueError, orZeroDivisionError, Python does not raise the error. - Enclosing
try...exceptblocks will never receive the error. - Code following the
withblock continues executing under the false assumption that all operations succeeded, leading to silent state corruption in production dashboards.
3. Vulnerable Source Code
# taipy/gui/gui.py lines 1554-1562
def __exit__(self, exc_type, exc_value, traceback):
try:
self.__send_messages()
except Exception as e: # pragma: no cover
_warn("Exception raised while sending messages", e)
if exc_value: # pragma: no cover
_warn(f"An {exc_type or 'Exception'} was raised", exc_value)
return True # <--- CRITICAL BUG: Suppresses any exception in 'with state:'!4. Minimal Reproduction Script
class MockGui:
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
# Mirroring taipy.gui.gui.Gui.__exit__
if exc_value:
print(f"[Warning Logged]: {exc_value}")
return True # Swallows exception!
gui = MockGui()
print("1. Starting batch update...")
try:
with gui:
print("2. Inside with state block...")
raise ValueError("Critical financial calculation failed!")
print("3. Never reached")
except ValueError:
print("Caught error in outer try/except!")
print("4. Execution continued despite failure! Outer try/except was bypassed!")
# The exception was completely swallowed, leaving the app in an inconsistent state.5. Proposed Fix (Git Patch)
diff --git a/taipy/gui/gui.py b/taipy/gui/gui.py
index b7c8d9e..f0a1b2c 100644
--- a/taipy/gui/gui.py
+++ b/taipy/gui/gui.py
@@ -1558,7 +1558,8 @@ class Gui:
_warn("Exception raised while sending messages", e)
if exc_value: # pragma: no cover
_warn(f"An {exc_type or 'Exception'} was raised", exc_value)
- return True
+ return False
+ return False
def __hold_messages(self):
grouping_message = self.__get_message_grouping()Bonus Architectural Findings (Honorable Mentions)
Beyond the 4 primary defects, the audit revealed 2 additional high-value issues in Taipy Core & GUI:
Bonus A: Loss of Custom Encoders on JSONDataNode Deserialization & No-Op Setters
- Files:
taipy/core/data/_data_converter.py:204, 212andtaipy/core/data/json.py:118-130 - Root Cause: When
JSONDataNodeis deserialized from the repository,_DataNodeConverterexplicitly writesNonefor keysencoderanddecoder. Becauseself._properties.get(key, _DefaultJSONEncoder)is used inJSONDataNode.__init__, if the key is present with valueNone, it evaluates toNonerather than the default_DefaultJSONEncoder. AnyEnumvalues fail to serialize on write. Furthermore,dn.encoder = NewEncodersetter only updatesself.propertiesbut does not update the cachedself._encoder, making dynamic encoder reassignment a silent no-op.
Bonus B: Subsecond Timeout Ineffectiveness in Job Orchestrator
- File:
taipy/core/_orchestrator/_orchestrator.py:208-212 - Root Cause: In
_wait_until_job_finished:def __check_if_timeout(st, to): if to is None: return True return (datetime.now() - st).seconds < totimedelta.secondsonly returns integer seconds (0 to 86399) and truncates microseconds. For subsecond timeouts (e.g.timeout=0.5),(datetime.now() - st).secondsremains0for the entire first second (0 < 0.5 == True). The timeout is incapable of triggering earlier than 1.0 second. The standard fix is to use(datetime.now() - st).total_seconds() < to.
Source: Avaiga/taipy