Skip to content

Only one subscriber can subscribe a published topic by send_all_on_topic #5303

@Hayashi-Yudai

Description

@Hayashi-Yudai

Duplicate Check

Describe the bug

Reading the documentation, it is noted that the specification of send_all_on_topic is to send a message to all subscribers who subscribe to the specified topic.

However, when I tried it, I found that only one subscriber can receive the paplyished message, and the behavior does not seem to match the specification.

Code sample

Code
import flet as ft


class Row1(ft.Row):
    def __init__(self, page: ft.Page):
        super().__init__()
        self.controls.append(ft.Container(ft.Text("Row1"), on_click=self.on_click_func))

        self.page = page

    def on_click_func(self, e: ft.ControlEvent):
        print("Row1 clicked")
        self.page.pubsub.send_all_on_topic("topic1", None)  # publisher


class Row2(ft.Row):
    def __init__(self, page: ft.Page):
        super().__init__()
        self.controls.append(ft.Text("Row2"))

        self.page = page
        self.page.pubsub.subscribe_topic("topic1", self.catch)  # subscriber 1

    def catch(self, topic: str, message: str):
        print(f"Row2 received message on {topic}: {message}")


class Row3(ft.Row):
    def __init__(self, page: ft.Page):
        super().__init__()
        self.controls.append(ft.Text("Row3"))

        self.page = page
        self.page.pubsub.subscribe_topic("topic1", self.catch)  # subscriber 2

    def catch(self, topic: str, message: str):
        print(f"Row3 received message on {topic}: {message}")


def main(page: ft.Page):
    row1 = Row1(page)
    row2 = Row2(page)
    row3 = Row3(page)

    page.add(ft.Column([row1, row2, row3]))


if __name__ == "__main__":
    ft.app(target=main)

To reproduce

Execute the code shown above and click on the text “Row1” that appears in the UI. Only “Row3 received message on topic1: None” is actually displayed.

Expected behavior

The expected behavior is to see two strings on the command line:

  • “Row2 received message on topic1: None”
  • “Row3 received message on topic1: None”

(because there are two subscribers for topic1).

Screenshots / Videos

Captures Image

Operating System

macOS

Operating system details

14.7(23H124)

Flet version

0.28.2

Regression

No, it isn't

Suggestions

No response

Logs

Logs
uv run debug/pubsub_test.py
Row1 clicked
Row3 received message on topic1: None

Additional details

No response

Metadata

Metadata

Assignees

Labels

enhancementImprovement/Optimization

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions