Skip to content

Commit

Permalink
Fix stream None base message (#6522)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored Mar 19, 2024
1 parent 310d9e9 commit 80d7257
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions panel/chat/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,9 @@ def stream(self, token: str, replace: bool = False):
object_panel = self
attr = "object"
obj = self.object
if obj is None:
obj = ""

while not isinstance(obj, str) or isinstance(object_panel, ImageBase):
object_panel = obj
if hasattr(obj, "objects"):
Expand Down
10 changes: 10 additions & 0 deletions panel/tests/chat/test_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ def test_stream_replace(self, chat_feed):
chat_feed.stream("Goodbye", message=message, replace=True)
wait_until(lambda: chat_feed.objects[-1].object == "Goodbye")

@pytest.mark.parametrize("replace", [True, False])
def test_stream_originally_none_message(self, chat_feed, replace):
def callback(contents, user, instance):
for i in range(3):
chat_feed.stream(f"{i}.", message=base_message, replace=replace)
chat_feed.callback = callback
base_message = ChatMessage()
chat_feed.send(base_message, respond=True)
assert chat_feed.objects[0].object == "2." if replace else "0.1.2."

@pytest.mark.parametrize(
"obj",
[
Expand Down

0 comments on commit 80d7257

Please sign in to comment.