Skip to content

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

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

Closed
1 task done
Hayashi-Yudai opened this issue May 14, 2025 · 1 comment
Closed
1 task done
Assignees
Labels
enhancement Improvement/Optimization
Milestone

Comments

@Hayashi-Yudai
Copy link

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

@FeodorFitsner FeodorFitsner self-assigned this May 14, 2025
@FeodorFitsner
Copy link
Contributor

Apparently, it's designed to have only one subscriber per topic, per session. So right now, it's your responsibility to "broadcast" the message within your session. However, I don't see a reason why we cannot improve that and allow multiple subscribers per session. Will do a fix.

@FeodorFitsner FeodorFitsner added the enhancement Improvement/Optimization label May 14, 2025
@FeodorFitsner FeodorFitsner added this to the Flet v0.28.3 milestone May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement/Optimization
Projects
None yet
Development

No branches or pull requests

2 participants