Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stream None base message #6522

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading