Tribler / tribler

Privacy enhanced BitTorrent client with P2P content discovery
https://www.tribler.org
GNU General Public License v3.0
4.73k stars 445 forks source link

[main] KeyError: 'ratio' (in `DownloadWidgetItem.__lt__`) #8026

Closed kozlovsky closed 1 month ago

kozlovsky commented 1 month ago

The error appears when right-clicking on the RATIO column's header in the downloads pane.

Traceback (most recent call last):
  File "C:\\dev\\tribler\\src\\tribler\\gui\\widgets\\downloadwidgetitem.py", line 132, in __lt__
    return float(self.download_info["ratio"]) > float(other.download_info["ratio"])
KeyError: 'ratio'

Here:

    def __lt__(self, other):
        # The download info might not be available yet or there could still be loading QTreeWidgetItem
        if not self.download_info or not isinstance(other, DownloadWidgetItem):
            return True
        elif not other.download_info:
            return False

        column = self.treeWidget().sortColumn()
        if column == 1:
            return float(self.download_info["size"]) > float(other.download_info["size"])
        elif column == 2:
            return int(self.download_info["progress"] * 100) > int(other.download_info["progress"] * 100)
        elif column == 4:
            return self.download_info["num_seeds"] > other.download_info["num_seeds"]
        elif column == 5:
            return self.download_info["num_peers"] > other.download_info["num_peers"]
        elif column == 6:
            return float(self.download_info["speed_down"]) > float(other.download_info["speed_down"])
        elif column == 7:
            return float(self.download_info["speed_up"]) > float(other.download_info["speed_up"])
        elif column == 8:
            return float(self.download_info["ratio"]) > float(other.download_info["ratio"])  # <-- here

The reason for the error is renaming the "ratio" dictionary field to all_time_ratio in #7817. We need to rename it here as well.