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

bug: AssertionError: assert self.__uid is not None #4794

Open
1 task done
ndonkoHenri opened this issue Jan 28, 2025 · 4 comments
Open
1 task done

bug: AssertionError: assert self.__uid is not None #4794

ndonkoHenri opened this issue Jan 28, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@ndonkoHenri
Copy link
Contributor

Duplicate Check

Describe the bug

An assertion error is raised when running the attached code.

Code sample

Code
import time
import flet as ft


class ChatMessage(ft.Row):
    def __init__(self, message: str):
        super().__init__()
        self.controls = [ft.CircleAvatar(content=ft.Text("U")), ft.Text(message)]


def main(page: ft.Page):
    def on_message(message: str):
        chat.controls.append(ChatMessage(message))
        page.update()

    page.pubsub.subscribe(on_message)

    chat = ft.ListView(
        expand=True,
        auto_scroll=True,
    )

    page.add(chat)
    for i in range(300):
        page.pubsub.send_all(f"message {i}")
        time.sleep(0.2)


ft.app(target=main)

To reproduce

Run the code, then wait for some time while observing the terminal.

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

macOS

Operating system details

15.0

Flet version

0.26.0

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/playground/test-b.py", line 15, in on_message
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/page.py", line 732, in update
    r = self.__update(self)
        ^^^^^^^^^^^^^^^^^^^
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/page.py", line 798, in __update
    commands, added_controls, removed_controls = self.__prepare_update(*controls)
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/page.py", line 814, in __prepare_update
    control.build_update_commands(
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 483, in build_update_commands
    ctrl.build_update_commands(
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 483, in build_update_commands
    ctrl.build_update_commands(
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 483, in build_update_commands
    ctrl.build_update_commands(
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 502, in build_update_commands
    assert self.__uid is not None
           ^^^^^^^^^^^^^^^^^^^^^^
AssertionError
Future exception was never retrieved
future: <Future finished exception=AssertionError()>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/playground/test-b.py", line 15, in on_message
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/page.py", line 732, in update
    r = self.__update(self)
        ^^^^^^^^^^^^^^^^^^^
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/page.py", line 798, in __update
    commands, added_controls, removed_controls = self.__prepare_update(*controls)
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/page.py", line 814, in __prepare_update
    control.build_update_commands(
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 483, in build_update_commands
    ctrl.build_update_commands(
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 483, in build_update_commands
    ctrl.build_update_commands(
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 483, in build_update_commands
    ctrl.build_update_commands(
  File "/Users/ndonkohenri/PycharmProjects/flet-dev/flet/sdk/python/packages/flet/src/flet/core/control.py", line 502, in build_update_commands
    assert self.__uid is not None

Additional details

Issue happens occasionally but very often.

@ndonkoHenri ndonkoHenri added the bug Something isn't working label Jan 28, 2025
@HappyCoder256
Copy link

I used to get this error and as am talking right now, I still run into it but the only temporary fix I discovered for it is to decrease on the consistent rates where your app's ui is updated or reduce on calling page.update consistently.

@omamkaz
Copy link
Contributor

omamkaz commented Jan 29, 2025

try to remove page.update() from on_message method!

@ndonkoHenri
Copy link
Contributor Author

try to remove page.update() from on_message method!

The UI won't get updated in that case. 😅

@HappyCoder256
Copy link

Try increasing the sleep value to something like 0.6. U'll not run into that error. The only reason why ure getting assertion is because you're trying to update the app's ui At the fastest rate in the way that the app is requesting a ui update even before completing the previous ui update request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants