gurudesh/pytracebugs huggingface dataset:
# Buggy code
def update_torrent_with_metainfo(self, infohash, metainfo):
    """Updates name, length and num files from metainfo if record does not exist in the database."""
    torrent_id = self.getTorrentID(infohash)
    name = self.getOne("name", torrent_id=torrent_id)
    if not name:
        num_files, length = 0, 0
        if "info" in metainfo:
            info = metainfo["info"]
            name = info["name"] if "name" in info else ""
            if "files" in info:
                num_files = len(info["files"])
                for piece in info["files"]:
                    length += piece["length"]

        if name and num_files and length:
            self.updateTorrent(
                infohash, notify=False, name=name, num_files=num_files, length=length
            )


# Traceback (RuntimeError)
Traceback (most recent call last):
File "TriblerGUI\event_request_manager.py", line 127, in on_read_data
RuntimeError: [Failure instance: Traceback: <type 'exceptions.UnicodeDecodeError'>: 'ascii' codec can't decode byte 0xc3 in position 17: ordinal not in range(128)
Tribler\Core\Libtorrent\LibtorrentMgr.py:591:_task_process_alerts
Tribler\Core\Libtorrent\LibtorrentMgr.py:539:got_metainfo
lib\site-packages\twisted\internet\defer.py:459:callback
lib\site-packages\twisted\internet\defer.py:567:_startRunCallbacks
--- <exception caught here> ---
lib\site-packages\twisted\internet\defer.py:653:_runCallbacks
Tribler\Core\Modules\restapi\torrentinfo_endpoint.py:70:on_got_metainfo
Tribler\Core\CacheDB\SqliteCacheDBHandler.py:533:update_torrent_with_metainfo
Tribler\Core\CacheDB\SqliteCacheDBHandler.py:513:updateTorrent
Tribler\Core\CacheDB\sqlitecachedb.py:370:update
Tribler\Core\CacheDB\sqlitecachedb.py:326:execute_write
Tribler\pyipv8\ipv8\util.py:14:helper
Tribler\pyipv8\ipv8\util.py:26:blockingCallFromThread
Tribler\Core\CacheDB\sqlitecachedb.py:295:execute
].

# Fixed code
def update_torrent_with_metainfo(self, infohash, metainfo):
    """Updates name, length and num files from metainfo if record does not exist in the database."""
    torrent_id = self.getTorrentID(infohash)
    name = self.getOne("name", torrent_id=torrent_id)
    if not name:
        num_files, length = 0, 0
        if "info" in metainfo:
            info = metainfo["info"]
            name = (
                "".join([unichr(ord(c)) for c in info["name"]])
                if "name" in info
                else ""
            )
            if "files" in info:
                num_files = len(info["files"])
                for piece in info["files"]:
                    length += piece["length"]

        if name and num_files and length:
            self.updateTorrent(
                infohash, notify=False, name=name, num_files=num_files, length=length
            )
# Buggy code
def on_balance_request_cell(self, source_address, data, _):
    payload = self._ez_unpack_noauth(BalanceRequestPayload, data, global_time=False)

    circuit_id = payload.circuit_id
    request = self.request_cache.get("anon-circuit", circuit_id)
    if request.should_forward:
        forwarding_relay = RelayRoute(request.from_circuit_id, request.peer)
        self.send_cell(
            [forwarding_relay.peer.address],
            "relay-balance-request",
            BalanceRequestPayload(forwarding_relay.circuit_id),
        )
    else:
        self.on_balance_request(payload)


# Traceback (AttributeError)
ERROR   1535358646.99                 community:680  (TriblerTunnelCommunity)  Exception occurred while handling packet!
Traceback (most recent call last):
File "/home/sandip/tudelft/tribler/Tribler/pyipv8/ipv8/messaging/anonymization/community.py", line 677, in on_packet_from_circuit
self.decode_map_private[data[22]](source_address, data, circuit_id)
File "/home/sandip/tudelft/tribler/Tribler/community/triblertunnel/community.py", line 184, in on_balance_request_cell
if request.should_forward:
AttributeError: 'NoneType' object has no attribute 'should_forward'

# Fixed code
def on_balance_request_cell(self, source_address, data, _):
    payload = self._ez_unpack_noauth(BalanceRequestPayload, data, global_time=False)

    circuit_id = payload.circuit_id
    request = self.request_cache.get("anon-circuit", circuit_id)
    if not request:
        self.logger.warning("Circuit creation cache for id %s not found!", circuit_id)
        return

    if request.should_forward:
        forwarding_relay = RelayRoute(request.from_circuit_id, request.peer)
        self.send_cell(
            [forwarding_relay.peer.address],
            "relay-balance-request",
            BalanceRequestPayload(forwarding_relay.circuit_id),
        )
    else:
        self.on_balance_request(payload)
# Buggy code
def get_files_completion(self):
    """Returns a list of filename, progress tuples indicating the progress
    for every file selected using set_selected_files. Progress is a float
    between 0 and 1
    """
    completion = []

    if self.lt_status:
        files = self.download.get_def().get_files_with_length()
        progress = self.download.handle.file_progress(flags=1)
        for index, (path, size) in enumerate(files):
            completion.append((path, float(progress[index]) / size))

    return completion


# Traceback (ZeroDivisionError)
ERROR   ...                  __init__:1198 (RESTRequest)  [Failure instance: Traceback: <type 'exceptions.ZeroDivisionError'>: float division by zero
twisted/protocols/basic.py:571:dataReceived
twisted/web/http.py:1752:lineReceived
twisted/web/http.py:1845:allContentReceived
twisted/web/http.py:766:requestReceived
--- <exception caught here> ---
twisted/web/server.py:190:process
twisted/web/server.py:241:render
twisted/web/resource.py:250:render
Tribler/Core/Modules/restapi/downloads_endpoint.py:255:render_GET
Tribler/Core/Modules/restapi/downloads_endpoint.py:93:get_files_info_json
Tribler/Core/DownloadState.py:163:get_files_completion
]
Traceback (most recent call last):
File "twisted/web/server.py", line 190, in process
File "twisted/web/server.py", line 241, in render
File "twisted/web/resource.py", line 250, in render
File "Tribler/Core/Modules/restapi/downloads_endpoint.py", line 255, in render_GET
File "Tribler/Core/Modules/restapi/downloads_endpoint.py", line 93, in get_files_info_json
File "Tribler/Core/DownloadState.py", line 163, in get_files_completion
ZeroDivisionError: float division by zero

# Fixed code
def get_files_completion(self):
    """Returns a list of filename, progress tuples indicating the progress
    for every file selected using set_selected_files. Progress is a float
    between 0 and 1
    """
    completion = []

    if self.lt_status:
        files = self.download.get_def().get_files_with_length()
        progress = self.download.handle.file_progress(flags=1)
        for index, (path, size) in enumerate(files):
            completion_frac = (float(progress[index]) / size) if size > 0 else 1
            completion.append((path, completion_frac))

    return completion
# Buggy code
def on_profiler_info(self, data):
    self.profiler_enabled = data["state"] == "STARTED"
    self.window().toggle_profiler_button.setEnabled(True)
    self.window().toggle_profiler_button.setText(
        "%s profiler" % ("Stop" if self.profiler_enabled else "Start")
    )


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_profiler_info(self, data):
    if not data:
        return
    self.profiler_enabled = data["state"] == "STARTED"
    self.window().toggle_profiler_button.setEnabled(True)
    self.window().toggle_profiler_button.setText(
        "%s profiler" % ("Stop" if self.profiler_enabled else "Start")
    )
# Buggy code
def on_profiler_state_changed(self, data):
    self.toggling_profiler = False
    self.window().toggle_profiler_button.setEnabled(True)
    self.load_profiler_tab()

    if "profiler_file" in data:
        QMessageBox.about(
            self,
            "Profiler statistics saved",
            "The profiler data has been saved to %s." % data["profiler_file"],
        )


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_profiler_state_changed(self, data):
    if not data:
        return
    self.toggling_profiler = False
    self.window().toggle_profiler_button.setEnabled(True)
    self.load_profiler_tab()

    if "profiler_file" in data:
        QMessageBox.about(
            self,
            "Profiler statistics saved",
            "The profiler data has been saved to %s." % data["profiler_file"],
        )
# Buggy code
def display_logs(self, data):
    tab_index = self.window().log_tab_widget.currentIndex()
    log_display_widget = (
        self.window().core_log_display_area
        if tab_index == 0
        else self.window().gui_log_display_area
    )

    log_display_widget.moveCursor(QTextCursor.End)

    key_content = "content"
    key_max_lines = "max_lines"

    if not key_content in data or not data[key_content]:
        log_display_widget.setPlainText("No logs found")
    else:
        log_display_widget.setPlainText(data[key_content])

    if not key_max_lines in data or not data[key_max_lines]:
        self.window().max_lines_value.setText("")
    else:
        self.window().max_lines_value.setText(str(data[key_max_lines]))

    sb = log_display_widget.verticalScrollBar()
    sb.setValue(sb.maximum())


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def display_logs(self, data):
    if not data:
        return
    tab_index = self.window().log_tab_widget.currentIndex()
    log_display_widget = (
        self.window().core_log_display_area
        if tab_index == 0
        else self.window().gui_log_display_area
    )

    log_display_widget.moveCursor(QTextCursor.End)

    key_content = "content"
    key_max_lines = "max_lines"

    if not key_content in data or not data[key_content]:
        log_display_widget.setPlainText("No logs found")
    else:
        log_display_widget.setPlainText(data[key_content])

    if not key_max_lines in data or not data[key_max_lines]:
        self.window().max_lines_value.setText("")
    else:
        self.window().max_lines_value.setText(str(data[key_max_lines]))

    sb = log_display_widget.verticalScrollBar()
    sb.setValue(sb.maximum())
# Buggy code
def on_report_sent(self, response):
    sent = response["sent"]

    success_text = "Successfully sent the report! Thanks for your contribution."
    error_text = "Could not send the report! Please post this issue on GitHub."

    box = QMessageBox(self.window())
    box.setWindowTitle("Report Sent" if sent else "ERROR: Report Sending Failed")
    box.setText(success_text if sent else error_text)
    box.setStyleSheet("QPushButton { color: white; }")
    box.exec_()

    QApplication.quit()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_report_sent(self, response):
    if not response:
        return
    sent = response["sent"]

    success_text = "Successfully sent the report! Thanks for your contribution."
    error_text = "Could not send the report! Please post this issue on GitHub."

    box = QMessageBox(self.window())
    box.setWindowTitle("Report Sent" if sent else "ERROR: Report Sending Failed")
    box.setText(success_text if sent else error_text)
    box.setStyleSheet("QPushButton { color: white; }")
    box.exec_()

    QApplication.quit()
# Buggy code
def received_settings(self, settings):
    # If we cannot receive the settings, stop Tribler with an option to send the crash report.
    if "error" in settings:
        raise RuntimeError(TriblerRequestManager.get_message_from_error(settings))

    self.tribler_settings = settings["settings"]

    # Set the video server port
    self.video_player_page.video_player_port = settings["ports"]["video_server~port"]

    # Disable various components based on the settings
    if not self.tribler_settings["search_community"]["enabled"]:
        self.window().top_search_bar.setHidden(True)
    if not self.tribler_settings["video_server"]["enabled"]:
        self.left_menu_button_video_player.setHidden(True)
    self.downloads_creditmining_button.setHidden(
        not self.tribler_settings["credit_mining"]["enabled"]
    )
    self.downloads_all_button.click()

    # process pending file requests (i.e. someone clicked a torrent file when Tribler was closed)
    # We do this after receiving the settings so we have the default download location.
    self.process_uri_request()

    # Set token balance refresh timer and load the token balance
    self.token_refresh_timer = QTimer()
    self.token_refresh_timer.timeout.connect(self.load_token_balance)
    self.token_refresh_timer.start(60000)

    self.load_token_balance()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def received_settings(self, settings):
    if not settings:
        return
    # If we cannot receive the settings, stop Tribler with an option to send the crash report.
    if "error" in settings:
        raise RuntimeError(TriblerRequestManager.get_message_from_error(settings))

    self.tribler_settings = settings["settings"]

    # Set the video server port
    self.video_player_page.video_player_port = settings["ports"]["video_server~port"]

    # Disable various components based on the settings
    if not self.tribler_settings["search_community"]["enabled"]:
        self.window().top_search_bar.setHidden(True)
    if not self.tribler_settings["video_server"]["enabled"]:
        self.left_menu_button_video_player.setHidden(True)
    self.downloads_creditmining_button.setHidden(
        not self.tribler_settings["credit_mining"]["enabled"]
    )
    self.downloads_all_button.click()

    # process pending file requests (i.e. someone clicked a torrent file when Tribler was closed)
    # We do this after receiving the settings so we have the default download location.
    self.process_uri_request()

    # Set token balance refresh timer and load the token balance
    self.token_refresh_timer = QTimer()
    self.token_refresh_timer.timeout.connect(self.load_token_balance)
    self.token_refresh_timer.start(60000)

    self.load_token_balance()
# Buggy code
def on_download_added(self, result):
    if (
        len(self.pending_uri_requests) == 0
    ):  # Otherwise, we first process the remaining requests.
        self.window().left_menu_button_downloads.click()
    else:
        self.process_uri_request()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_download_added(self, result):
    if not result:
        return
    if (
        len(self.pending_uri_requests) == 0
    ):  # Otherwise, we first process the remaining requests.
        self.window().left_menu_button_downloads.click()
    else:
        self.process_uri_request()
# Buggy code
def received_playlists_in_channel(self, results):
    for result in results["playlists"]:
        self.playlists.append((PlaylistListItem, result))
    self.loaded_playlists = True
    self.update_result_list()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def received_playlists_in_channel(self, results):
    if not results:
        return
    for result in results["playlists"]:
        self.playlists.append((PlaylistListItem, result))
    self.loaded_playlists = True
    self.update_result_list()
# Buggy code
def on_torrent_created(self, result):
    self.window().edit_channel_create_torrent_button.setEnabled(True)
    if "torrent" in result:
        self.add_torrent_to_channel(result["torrent"])


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_torrent_created(self, result):
    if not result:
        return
    self.window().edit_channel_create_torrent_button.setEnabled(True)
    if "torrent" in result:
        self.add_torrent_to_channel(result["torrent"])
# Buggy code
def on_torrent_to_channel_added(self, result):
    self.window().edit_channel_create_torrent_progress_label.hide()
    if "added" in result:
        self.window().edit_channel_details_stacked_widget.setCurrentIndex(
            PAGE_EDIT_CHANNEL_TORRENTS
        )
        self.window().edit_channel_page.load_channel_torrents()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_torrent_to_channel_added(self, result):
    if not result:
        return
    self.window().edit_channel_create_torrent_progress_label.hide()
    if "added" in result:
        self.window().edit_channel_details_stacked_widget.setCurrentIndex(
            PAGE_EDIT_CHANNEL_TORRENTS
        )
        self.window().edit_channel_page.load_channel_torrents()
# Buggy code
def initialize_with_channel_overview(self, overview):
    if "error" in overview:
        self.window().edit_channel_stacked_widget.setCurrentIndex(0)
    else:
        if "mychannel" in overview:
            self.channel_overview = overview["mychannel"]
            self.set_editing_own_channel(True)
            self.window().edit_channel_name_label.setText("My channel")
        else:
            self.channel_overview = overview["channel"]
            self.set_editing_own_channel(False)
            self.window().edit_channel_name_label.setText(self.channel_overview["name"])

        self.window().edit_channel_overview_name_label.setText(
            self.channel_overview["name"]
        )
        self.window().edit_channel_description_label.setText(
            self.channel_overview["description"]
        )
        self.window().edit_channel_identifier_label.setText(
            self.channel_overview["identifier"]
        )

        self.window().edit_channel_name_edit.setText(self.channel_overview["name"])
        self.window().edit_channel_description_edit.setText(
            self.channel_overview["description"]
        )

        self.window().edit_channel_stacked_widget.setCurrentIndex(1)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def initialize_with_channel_overview(self, overview):
    if not overview:
        return
    if "error" in overview:
        self.window().edit_channel_stacked_widget.setCurrentIndex(0)
    else:
        if "mychannel" in overview:
            self.channel_overview = overview["mychannel"]
            self.set_editing_own_channel(True)
            self.window().edit_channel_name_label.setText("My channel")
        else:
            self.channel_overview = overview["channel"]
            self.set_editing_own_channel(False)
            self.window().edit_channel_name_label.setText(self.channel_overview["name"])

        self.window().edit_channel_overview_name_label.setText(
            self.channel_overview["name"]
        )
        self.window().edit_channel_description_label.setText(
            self.channel_overview["description"]
        )
        self.window().edit_channel_identifier_label.setText(
            self.channel_overview["identifier"]
        )

        self.window().edit_channel_name_edit.setText(self.channel_overview["name"])
        self.window().edit_channel_description_edit.setText(
            self.channel_overview["description"]
        )

        self.window().edit_channel_stacked_widget.setCurrentIndex(1)
# Buggy code
def initialize_with_torrents(self, torrents):
    self.window().edit_channel_torrents_list.set_data_items([])

    items = []
    for result in torrents["torrents"]:
        items.append(
            (
                ChannelTorrentListItem,
                result,
                {
                    "show_controls": True,
                    "on_remove_clicked": self.on_torrent_remove_clicked,
                },
            )
        )
    self.window().edit_channel_torrents_list.set_data_items(items)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def initialize_with_torrents(self, torrents):
    if not torrents:
        return
    self.window().edit_channel_torrents_list.set_data_items([])

    items = []
    for result in torrents["torrents"]:
        items.append(
            (
                ChannelTorrentListItem,
                result,
                {
                    "show_controls": True,
                    "on_remove_clicked": self.on_torrent_remove_clicked,
                },
            )
        )
    self.window().edit_channel_torrents_list.set_data_items(items)
# Buggy code
def initialize_with_playlists(self, playlists):
    self.playlists_loaded.emit(playlists)
    self.playlists = playlists
    self.window().edit_channel_playlists_list.set_data_items([])

    self.update_playlist_list()

    viewing_playlist_index = self.get_index_of_viewing_playlist()
    if viewing_playlist_index != -1:
        self.viewing_playlist = self.playlists["playlists"][viewing_playlist_index]
        self.update_playlist_torrent_list()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def initialize_with_playlists(self, playlists):
    if not playlists:
        return
    self.playlists_loaded.emit(playlists)
    self.playlists = playlists
    self.window().edit_channel_playlists_list.set_data_items([])

    self.update_playlist_list()

    viewing_playlist_index = self.get_index_of_viewing_playlist()
    if viewing_playlist_index != -1:
        self.viewing_playlist = self.playlists["playlists"][viewing_playlist_index]
        self.update_playlist_torrent_list()
# Buggy code
def initialize_with_rss_feeds(self, rss_feeds):
    self.window().edit_channel_rss_feeds_list.clear()
    for feed in rss_feeds["rssfeeds"]:
        item = QTreeWidgetItem(self.window().edit_channel_rss_feeds_list)
        item.setText(0, feed["url"])

        self.window().edit_channel_rss_feeds_list.addTopLevelItem(item)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def initialize_with_rss_feeds(self, rss_feeds):
    if not rss_feeds:
        return
    self.window().edit_channel_rss_feeds_list.clear()
    for feed in rss_feeds["rssfeeds"]:
        item = QTreeWidgetItem(self.window().edit_channel_rss_feeds_list)
        item.setText(0, feed["url"])

        self.window().edit_channel_rss_feeds_list.addTopLevelItem(item)
# Buggy code
def on_channel_created(self, result):
    if "added" in result:
        self.window().create_channel_button.setEnabled(True)
        self.load_my_channel_overview()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_channel_created(self, result):
    if not result:
        return
    if "added" in result:
        self.window().create_channel_button.setEnabled(True)
        self.load_my_channel_overview()
# Buggy code
def on_channel_edited(self, result):
    if "modified" in result:
        self.window().edit_channel_name_label.setText(
            self.window().edit_channel_name_edit.text()
        )
        self.window().edit_channel_description_label.setText(
            self.window().edit_channel_description_edit.toPlainText()
        )


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_channel_edited(self, result):
    if not result:
        return
    if "modified" in result:
        self.window().edit_channel_name_label.setText(
            self.window().edit_channel_name_edit.text()
        )
        self.window().edit_channel_description_label.setText(
            self.window().edit_channel_description_edit.toPlainText()
        )
# Buggy code
def on_torrent_to_channel_added(self, result):
    if "added" in result:
        self.load_channel_torrents()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_torrent_to_channel_added(self, result):
    if not result:
        return
    if "added" in result:
        self.load_channel_torrents()
# Buggy code
def on_playlist_torrent_removed(self, result, torrent):
    self.remove_torrent_from_playlist(torrent)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_playlist_torrent_removed(self, result, torrent):
    if not result:
        return
    self.remove_torrent_from_playlist(torrent)
# Buggy code
def on_playlist_created(self, json_result):
    if "created" in json_result and json_result["created"]:
        self.on_playlist_edited_done()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_playlist_created(self, json_result):
    if not json_result:
        return
    if "created" in json_result and json_result["created"]:
        self.on_playlist_edited_done()
# Buggy code
def on_playlist_edited(self, json_result):
    if "modified" in json_result and json_result["modified"]:
        self.on_playlist_edited_done()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_playlist_edited(self, json_result):
    if not json_result:
        return
    if "modified" in json_result and json_result["modified"]:
        self.on_playlist_edited_done()
# Buggy code
def on_playlist_removed(self, json_result):
    if "removed" in json_result and json_result["removed"]:
        self.load_channel_playlists()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_playlist_removed(self, json_result):
    if not json_result:
        return
    if "removed" in json_result and json_result["removed"]:
        self.load_channel_playlists()
# Buggy code
def on_torrent_removed(self, json_result):
    if "removed" in json_result and json_result["removed"]:
        self.load_channel_torrents()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_torrent_removed(self, json_result):
    if not json_result:
        return
    if "removed" in json_result and json_result["removed"]:
        self.load_channel_torrents()
# Buggy code
def on_rss_feed_added(self, json_result):
    if json_result["added"]:
        self.load_channel_rss_feeds()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_rss_feed_added(self, json_result):
    if not json_result:
        return
    if json_result["added"]:
        self.load_channel_rss_feeds()
# Buggy code
def on_rss_feed_removed(self, json_result):
    if json_result["removed"]:
        self.load_channel_rss_feeds()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_rss_feed_removed(self, json_result):
    if not json_result:
        return
    if json_result["removed"]:
        self.load_channel_rss_feeds()
# Buggy code
def on_rss_feeds_refreshed(self, json_result):
    if json_result["rechecked"]:
        self.window().edit_channel_details_rss_refresh_button.setEnabled(True)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_rss_feeds_refreshed(self, json_result):
    if not json_result:
        return
    if json_result["rechecked"]:
        self.window().edit_channel_details_rss_refresh_button.setEnabled(True)
# Buggy code
def received_popular_channels(self, result):
    self.show_channels = True
    if not self.has_loaded_cells:
        self.load_cells()

    if len(result["channels"]) == 0:
        self.set_no_results_table(label_text="No recommended channels")
        return

    cur_ind = 0
    for channel in result["channels"][:9]:
        self.window().home_page_table_view.cellWidget(
            cur_ind % 3, cur_ind / 3
        ).update_with_channel(channel)
        cur_ind += 1

    self.window().resizeEvent(None)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def received_popular_channels(self, result):
    if not result:
        return
    self.show_channels = True
    if not self.has_loaded_cells:
        self.load_cells()

    if len(result["channels"]) == 0:
        self.set_no_results_table(label_text="No recommended channels")
        return

    cur_ind = 0
    for channel in result["channels"][:9]:
        self.window().home_page_table_view.cellWidget(
            cur_ind % 3, cur_ind / 3
        ).update_with_channel(channel)
        cur_ind += 1

    self.window().resizeEvent(None)
# Buggy code
def received_popular_torrents(self, result):
    self.show_channels = False
    if not self.has_loaded_cells:
        self.load_cells()

    if len(result["torrents"]) == 0:
        self.set_no_results_table(label_text="No recommended torrents")
        return

    cur_ind = 0
    for torrent in result["torrents"][:9]:
        self.window().home_page_table_view.cellWidget(
            cur_ind % 3, cur_ind / 3
        ).update_with_torrent(torrent)
        cur_ind += 1

    self.window().resizeEvent(None)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def received_popular_torrents(self, result):
    if not result:
        return
    self.show_channels = False
    if not self.has_loaded_cells:
        self.load_cells()

    if len(result["torrents"]) == 0:
        self.set_no_results_table(label_text="No recommended torrents")
        return

    cur_ind = 0
    for torrent in result["torrents"][:9]:
        self.window().home_page_table_view.cellWidget(
            cur_ind % 3, cur_ind / 3
        ).update_with_torrent(torrent)
        cur_ind += 1

    self.window().resizeEvent(None)
# Buggy code
def on_received_files(self, files):
    if "files" not in files or not files["files"]:
        return

    if self.files_request_timer:
        self.files_request_timer.stop()
        self.files_request_timer = None

    self.set_files(files["files"])
    self.loaded_list = True
    self.loading_list = False
    self.list_loaded.emit()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_received_files(self, files):
    if not files:
        return
    if "files" not in files or not files["files"]:
        return

    if self.files_request_timer:
        self.files_request_timer.stop()
        self.files_request_timer = None

    self.set_files(files["files"])
    self.loaded_list = True
    self.loading_list = False
    self.list_loaded.emit()
# Buggy code
def on_received_channel_torrents(self, result):
    self.torrents_in_playlist = self.playlist_info["torrents"]

    self.torrents_in_channel = []
    for torrent in result["torrents"]:
        if not ManagePlaylistPage.list_contains_torrent(
            self.torrents_in_playlist, torrent
        ):
            self.torrents_in_channel.append(torrent)

    self.update_lists()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_received_channel_torrents(self, result):
    if not result:
        return
    self.torrents_in_playlist = self.playlist_info["torrents"]

    self.torrents_in_channel = []
    for torrent in result["torrents"]:
        if not ManagePlaylistPage.list_contains_torrent(
            self.torrents_in_playlist, torrent
        ):
            self.torrents_in_channel.append(torrent)

    self.update_lists()
# Buggy code
def on_request_done(self, _):
    self.requests_done += 1
    if self.requests_done == len(self.pending_requests):
        self.on_requests_done()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_request_done(self, result):
    if not result:
        return
    self.requests_done += 1
    if self.requests_done == len(self.pending_requests):
        self.on_requests_done()
# Buggy code
def on_received_orders(self, orders):
    for order in orders["orders"]:
        if self.wallets:
            asset1_prec = self.wallets[order["assets"]["first"]["type"]]["precision"]
            asset2_prec = self.wallets[order["assets"]["second"]["type"]]["precision"]
            item = OrderWidgetItem(
                self.window().market_orders_list, order, asset1_prec, asset2_prec
            )
            self.window().market_orders_list.addTopLevelItem(item)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_received_orders(self, orders):
    if not orders:
        return
    for order in orders["orders"]:
        if self.wallets:
            asset1_prec = self.wallets[order["assets"]["first"]["type"]]["precision"]
            asset2_prec = self.wallets[order["assets"]["second"]["type"]]["precision"]
            item = OrderWidgetItem(
                self.window().market_orders_list, order, asset1_prec, asset2_prec
            )
            self.window().market_orders_list.addTopLevelItem(item)
# Buggy code
def on_order_cancelled(self, response):
    self.load_orders()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_order_cancelled(self, response):
    if not response:
        return
    self.load_orders()
# Buggy code
def on_received_asks(self, asks):
    self.asks = asks["asks"]
    self.update_filter_asks_list()
    self.update_filter_bids_list()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_received_asks(self, asks):
    if not asks:
        return
    self.asks = asks["asks"]
    self.update_filter_asks_list()
    self.update_filter_bids_list()
# Buggy code
def on_received_bids(self, bids):
    self.bids = bids["bids"]
    self.update_filter_asks_list()
    self.update_filter_bids_list()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_received_bids(self, bids):
    if not bids:
        return
    self.bids = bids["bids"]
    self.update_filter_asks_list()
    self.update_filter_bids_list()
# Buggy code
def on_order_created(self, response, is_ask):
    if is_ask:
        self.load_asks()
    else:
        self.load_bids()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_order_created(self, response, is_ask):
    if not response:
        return
    if is_ask:
        self.load_asks()
    else:
        self.load_bids()
# Buggy code
def on_received_transactions(self, transactions):
    for transaction in transactions["transactions"]:
        if self.wallets:
            asset1_prec = self.wallets[transaction["assets"]["first"]["type"]][
                "precision"
            ]
            asset2_prec = self.wallets[transaction["assets"]["second"]["type"]][
                "precision"
            ]
            item = TransactionWidgetItem(
                self.window().market_transactions_list,
                transaction,
                asset1_prec,
                asset2_prec,
            )
            self.window().market_transactions_list.addTopLevelItem(item)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_received_transactions(self, transactions):
    if not transactions:
        return
    for transaction in transactions["transactions"]:
        if self.wallets:
            asset1_prec = self.wallets[transaction["assets"]["first"]["type"]][
                "precision"
            ]
            asset2_prec = self.wallets[transaction["assets"]["second"]["type"]][
                "precision"
            ]
            item = TransactionWidgetItem(
                self.window().market_transactions_list,
                transaction,
                asset1_prec,
                asset2_prec,
            )
            self.window().market_transactions_list.addTopLevelItem(item)
# Buggy code
def on_received_payments(self, payments):
    for payment in payments["payments"]:
        self.add_payment_to_list(payment)


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_received_payments(self, payments):
    if not payments:
        return
    for payment in payments["payments"]:
        self.add_payment_to_list(payment)
# Buggy code
def on_wallets(self, wallets):
    self.wallets = wallets["wallets"]

    if "MB" in self.wallets and self.wallets["MB"]["created"]:
        self.window().wallet_mc_overview_button.show()

    if "BTC" in self.wallets and self.wallets["BTC"]["created"]:
        self.window().wallet_btc_overview_button.show()

    if "TBTC" in self.wallets and self.wallets["TBTC"]["created"]:
        self.window().wallet_tbtc_overview_button.show()

    # Find out which wallets we still can create
    self.wallets_to_create = []
    for identifier, wallet in self.wallets.iteritems():
        if not wallet["created"]:
            self.wallets_to_create.append(identifier)

    if len(self.wallets_to_create) > 0:
        self.window().add_wallet_button.setEnabled(True)
    else:
        self.window().add_wallet_button.hide()


# Traceback (TypeError)
ERROR   1533554928.15            tribler_window:90   (root)  Traceback (most recent call last):
File "C:\Users\goqs\Documents\tribler\TriblerGUI\widgets\subscribedchannelspage.py", line 34, in received_subscribed_channels
if len(results['subscribed']) == 0:
TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def on_wallets(self, wallets):
    if not wallets:
        return
    self.wallets = wallets["wallets"]

    if "MB" in self.wallets and self.wallets["MB"]["created"]:
        self.window().wallet_mc_overview_button.show()

    if "BTC" in self.wallets and self.wallets["BTC"]["created"]:
        self.window().wallet_btc_overview_button.show()

    if "TBTC" in self.wallets and self.wallets["TBTC"]["created"]:
        self.window().wallet_tbtc_overview_button.show()

    # Find out which wallets we still can create
    self.wallets_to_create = []
    for identifier, wallet in self.wallets.iteritems():
        if not wallet["created"]:
            self.wallets_to_create.append(identifier)

    if len(self.wallets_to_create) > 0:
        self.window().add_wallet_button.setEnabled(True)
    else:
        self.window().add_wallet_button.hide()