Skip to content

[🐛 BUG] Async callback submodule scoping issue #2866

@arcanaxion

Description

@arcanaxion

🔍 What went wrong?

When using async callback in a submodule/page, the state cannot access its state variables.

# main.py
from pages import home
from taipy.gui import Gui, State


def on_change(state: State, var_name: str, var_value):
    print(var_name, type(var_value), var_value)


pages = {"/": "", "home": home.home_page}

if __name__ == "__main__":
    gui = Gui(pages=pages)
    gui.run(run_browser=False)
# pages/home.py
import time

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

counter = 0


async def count_to_10(state: State):
    for i in range(10):
        state.counter = i + 1
        time.sleep(1)


with tgb.Page() as home_page:
    tgb.button("Count to 10", on_action=count_to_10)
    tgb.text("{counter}")

Click button, then console:

/home/testbench/.venv-git-2026-02-24/lib/python3.12/site-packages/taipy/gui/gui.py:2340: TaipyGuiWarning: Variable 'counter' is not available in the '__main__' module.
  _warn(

📦 Taipy Version

develop

📋 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions