Skip to content

Doubleclick in Table and Tree with data==None triggers IndexError #3905

Description

@areslagae

Describe the bug

doubleclick in table with data==None triggers IndexError

example below results in error below

this might be by design, but since None is an acceptable value for data per the documentation, and it makes perfect sense to have an empty table in an application (mine is empty until the user triggers a db query), this behavior is unexpected to me

not a disaster - why would a user click there anyway If there is no data - but also not great since it crashes the application

Traceback (most recent call last):
  File ".../.venv/lib/python3.14/site-packages/rubicon/objc/api.py", line 412, in __call__
    result = self.py_method(py_self, *args)
  File ".../.venv/lib/python3.14/site-packages/toga_cocoa/widgets/table.py", line 127, in onDoubleClick_
    clicked = self.interface.data[self.clickedRow]
  File ".../.venv/lib/python3.14/site-packages/toga/sources/list_source.py", line 135, in __getitem__
    return self._data[index]
IndexError: list index out of range

Steps to reproduce

import toga

class MyApp(toga.App):
    def startup(self):
        self.main_window = toga.MainWindow()
        self.main_window.content = toga.Table(
            headings=["Name", "Age"],
            # data=[
            #     ("Arthur Dent", 42),
            #     ("Ford Prefect", 37),
            #     ("Tricia McMillan", 38),
            # ],
            data=None,
            multiple_select=False,
        )        
        self.main_window.show()

if __name__ == '__main__':
    app = MyApp("Realistic App", "org.beeware.realistic")
    app.main_loop()

Expected behavior

no exception

Screenshots

No response

Environment

macOS 24.6.0
Python 3.14.0 (main, Oct 7 2025, 09:34:52) [Clang 17.0.0 (clang-1700.0.13.3)] on darwin
Toga: toga-0.5.2

Logs


Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA crash or error in behavior.macOSThe issue relates to Apple macOS support.
    No fields configured for issues without a type.

    Projects

    Status
    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions