diff --git a/panel/chat/step.py b/panel/chat/step.py index e98bcfb172..bf35493002 100644 --- a/panel/chat/step.py +++ b/panel/chat/step.py @@ -157,7 +157,7 @@ def __exit__(self, exc_type, exc_value, tb): self.status = "failed" if self.context_exception == "raise": return False - else: + elif self.status in ("pending", "running"): self.status = "success" return True # suppress exception if any diff --git a/panel/tests/chat/test_step.py b/panel/tests/chat/test_step.py index 017353d85d..885da32f22 100644 --- a/panel/tests/chat/test_step.py +++ b/panel/tests/chat/test_step.py @@ -94,6 +94,12 @@ def test_repeated_error(self): assert step.title == "Error: 'RuntimeError'", "Title should update to 'Error: 'RuntimeError'' on failure again" assert step.objects[0].object == "Testing\nSecond Testing", "Error message should be streamed to the message pane" + def test_context_manually_set_failed(self): + step = ChatStep() + with step: + step.status = "failed" + assert step.status == "failed", "Status should be 'failed' after manually setting it to 'failed'" + def test_context_exception_ignore(self): step = ChatStep(context_exception="ignore") with step: