flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
11.39k stars 445 forks source link

Dropdown option removal/add: AssertionError: _process_remove_command: control with ID '_474' not found. #4010

Closed tobsome closed 1 month ago

tobsome commented 1 month ago

Duplicate Check

Describe the bug

Hi guys,

when I want to remove an option from my dropdown I'm getting the following error: AssertionError: _process_remove_command: control with ID '_474' not found.

I created my dropdown menu exactly like in your example but I'm not able to add/remove, it always throws the error which seems to be based on the page update self.page.update() after the option has been removed. Without update the code works but dropdown is not going to be refreshed, of course.

Full error message:

future: <Future finished exception=AssertionError("_process_remove_command: control with ID '_474' not found.")>
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.12/3.12.4/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/XXX/env/lib/python3.12/site-packages/flet_core/page.py", line 944, in wrapper
    handler(*args)
  File "/Users/XXX/env/lib/python3.12/site-packages/config_manager_gui.py", line 324, in on_delete_click
    self.remove_option_from_dropdowns(selected_name)
  File "/Users/XXX/env/lib/python3.12/site-packages/config_manager_gui.py", line 345, in remove_option_from_dropdowns
    self.page.update()
  File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet_core/page.py", line 719, in update
    r = self.__update(self)
        ^^^^^^^^^^^^^^^^^^^
  File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet_core/page.py", line 835, in __update
    results = self.__conn.send_commands(self._session_id, commands).results
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet/fastapi/flet_app.py", line 407, in send_commands
    result, message = self._process_command(command)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet_core/local_connection.py", line 93, in _process_command
    return self._process_remove_command(command.values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet/fastapi/flet_app.py", line 361, in _process_remove_command
    control is not None
AssertionError: _process_remove_command: control with ID '_474' not found.

Code sample

Code ```python def on_delete_click(self, event): if not self.is_admin: return selected_name = self.departments_teams_dropdown.value # print(selected_name) if selected_name: # Delete the selected department/team from the database db_operations.delete_onboarding_department_team(selected_name) # Remove the option from the dropdowns self.remove_option_from_dropdowns(selected_name) # Clear the config fields # self.clear_config_fields() # Update the UI state # self.set_controls_state(True) def find_option(self, option_name): for option in self.departments_teams_dropdown.options: if option_name == option.key: return option return None def remove_option_from_dropdowns(self, option_name): # Remove from departments_teams_dropdown option = self.find_option(option_name) if option: print(self.departments_teams_dropdown.options) print(option) self.departments_teams_dropdown.options.remove(option) self.page.update() ```

To reproduce

Creating a dropdown a trying to add/remove options.

Expected behavior

Dropdown option added/removed.

Screenshots / Videos

Captures [Upload media here]

Operating System

macOS

Operating system details

macOS 15

Flet version

Version: 0.24.1

Regression

No, it isn't

Suggestions

No response

Logs

Logs ```console future: Traceback (most recent call last): File "/opt/homebrew/Cellar/python@3.12/3.12.4/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/XXX/env/lib/python3.12/site-packages/flet_core/page.py", line 944, in wrapper handler(*args) File "/Users/XXX/env/lib/python3.12/site-packages/config_manager_gui.py", line 324, in on_delete_click self.remove_option_from_dropdowns(selected_name) File "/Users/XXX/env/lib/python3.12/site-packages/config_manager_gui.py", line 345, in remove_option_from_dropdowns self.page.update() File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet_core/page.py", line 719, in update r = self.__update(self) ^^^^^^^^^^^^^^^^^^^ File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet_core/page.py", line 835, in __update results = self.__conn.send_commands(self._session_id, commands).results ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet/fastapi/flet_app.py", line 407, in send_commands result, message = self._process_command(command) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet_core/local_connection.py", line 93, in _process_command return self._process_remove_command(command.values) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/XXX/env/lib/python3.12/site-packages/env/lib/python3.12/site-packages/flet/fastapi/flet_app.py", line 361, in _process_remove_command control is not None AssertionError: _process_remove_command: control with ID '_474' not found. ```

Additional details

No response

ndonkoHenri commented 1 month ago

Please come up with a runnable repro if the issue so we can try.