Skip to content

[🐛 BUG] var_name renders as empty string in chat's on_action's callback #2584

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

Open
1 of 6 tasks
enarroied opened this issue Apr 26, 2025 · 0 comments
Open
1 of 6 tasks
Labels
🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟨 Priority: Medium Not blocking but should be addressed

Comments

@enarroied
Copy link

enarroied commented Apr 26, 2025

🔍 What went wrong?

When using the chat visual element, I can trigger a callback, it's the on_action parameter.
According to the documentation, the callback's signature has a var_name argument in the second position, and it references the name of the messages variable. However, it returns an empty string instead.

✅ Expected Behavior

It should return the name of the variable :)

🔄 Steps to Reproduce

The following code reproduces the issue, just send messages and check the terminal, the strings for var_name are empty, but the variable has a name (it can't not have it):

from taipy.gui import Gui
from taipy.gui import builder as tgb


def say_hi():
    return "hi"


def chat(state, var_name: str, payload: dict):
    # Retrieve the callback parameters
    print(var_name)  # Prints nothing (empty line)
    print(len(var_name))  # It's has 0 length, it's coherent with the empty line
    print(type(var_name))  # It's a string indeed

    (_, _, user_message, sender_id) = payload.get("args", [])
    # Add the input content as a sent message
    messages.append((f"{len(messages)}", user_message, sender_id))

    try:
        result_message = say_hi()
    except Exception:
        result_message = "There was a problem!"
    messages.append((f"{len(messages)}", result_message, users[1]))
    state.messages = messages


with tgb.Page() as chat_page:
    tgb.text("# PII Analyzer", mode="md")
    tgb.html("hr")
    tgb.chat(
        messages="{messages}",
        users="{users}",
        show_sender=True,
        sender_id="{users[0]}",
        on_action=chat,
        mode="markdown",
    )

if __name__ == "__main__":
    users = ["User", "Bot"]

    messages = []  # This is the message variable, its name is "messages"
    gui = Gui(chat_page)
    gui.run(title="var_name not showing", dark_mode=False, use_reloader=True)

💻 Runtime Environment

Lubuntu 24.04

🌐 Browser (if applicable)

Brave

🖥️ Operating System

Linux

📦 Taipy Version

4.0.2 and 4.0.3

📋 Additional Context (Optional)

📜 Code of Conduct

  • I have checked the existing issues to avoid duplicates.
  • I am willing to work on this issue (optional)

✅ Acceptance Criteria

  • A reproducible unit test is added.
  • Code coverage is at least 90%.
  • The bug reporter validated the fix.
  • Relevant documentation updates or an issue created in
@FlorianJacta FlorianJacta added 🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟨 Priority: Medium Not blocking but should be addressed labels Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖰 GUI Related to GUI 💥Malfunction Addresses an identified problem. 🟨 Priority: Medium Not blocking but should be addressed
Projects
None yet
Development

No branches or pull requests

2 participants