# Buggy code
def _on_selection_changed(self, selected, deselected):
    selected_indices = self.table_view.selectedIndexes()
    if not selected_indices:
        self.table_view.clearSelection()
        return

    data_item = selected_indices[-1].model().data_items[selected_indices[-1].row()]
    if "type" in data_item and data_item["type"] != REGULAR_TORRENT:
        return

    # Trigger health check if necessary
    # When the user scrolls the list, we only want to trigger health checks on the line
    # that the user stopped on, so we do not generate excessive health checks.
    if (
        data_item["last_tracker_check"] == 0
        and data_item.get("health") != HEALTH_CHECKING
    ):
        if self.healthcheck_cooldown.isActive():
            self.healthcheck_cooldown.stop()
        else:
            self.check_torrent_health(data_item)
        self.healthcheck_cooldown.start(HEALTHCHECK_DELAY_MS)


# Traceback (KeyError)
Traceback (most recent call last):,
File "src\run_tribler.py", line 179, in <module>,
File "src\tribler-gui\tribler_gui\utilities.py", line 382, in trackback_wrapper,
File "src\tribler-gui\tribler_gui\event_request_manager.py", line 116, in on_read_data,
File "src\tribler-gui\tribler_gui\event_request_manager.py", line 77, in tribler_started_event,
File "src\tribler-gui\tribler_gui\utilities.py", line 382, in trackback_wrapper,
File "src\tribler-gui\tribler_gui\tribler_window.py", line 488, in on_tribler_started,
File "src\tribler-gui\tribler_gui\widgets\channelcontentswidget.py", line 124, in initialize_content_page,
File "src\tribler-gui\tribler_gui\widgets\triblertablecontrollers.py", line 297, in __init__,
File "src\tribler-gui\tribler_gui\widgets\triblertablecontrollers.py", line 93, in __init__,
File "src\tribler-gui\tribler_gui\widgets\triblertablecontrollers.py", line 195, in __init__,
File "src\tribler-gui\tribler_gui\widgets\triblertablecontrollers.py", line 53, in __init__,
tribler_gui.utilities.CreationTraceback,
The above exception was the direct cause of the following exception:,
Traceback (most recent call last):,
File "src\tribler-gui\tribler_gui\utilities.py", line 385, in trackback_wrapper,
File "src\tribler-gui\tribler_gui\utilities.py", line 382, in trackback_wrapper,
File "src\tribler-gui\tribler_gui\widgets\triblertablecontrollers.py", line 54, in <lambda>,
File "src\tribler-gui\tribler_gui\widgets\triblertablecontrollers.py", line 135, in check_torrent_health,
KeyError: 'infohash'

# Fixed code
def _on_selection_changed(self, selected, deselected):
    selected_indices = self.table_view.selectedIndexes()
    if not selected_indices:
        self.table_view.clearSelection()
        return

    data_item = selected_indices[-1].model().data_items[selected_indices[-1].row()]
    if not dict_item_is_any_of(data_item, "type", [REGULAR_TORRENT]):
        return

    # Trigger health check if necessary
    # When the user scrolls the list, we only want to trigger health checks on the line
    # that the user stopped on, so we do not generate excessive health checks.
    if (
        data_item["last_tracker_check"] == 0
        and data_item.get("health") != HEALTH_CHECKING
    ):
        if self.healthcheck_cooldown.isActive():
            self.healthcheck_cooldown.stop()
        else:
            self.check_torrent_health(data_item)
        self.healthcheck_cooldown.start(HEALTHCHECK_DELAY_MS)