# Buggy code
def update_from_torrent_search_results(self, search_results):
    """
    Updates the torrent database with the provided search results. It also checks for conflicting torrents, meaning
    if torrent already exists in the database, we simply ignore the search result.
    """
    for result in search_results:
        (
            infohash,
            name,
            length,
            num_files,
            category_list,
            creation_date,
            seeders,
            leechers,
            cid,
        ) = result
        torrent_item = SearchResponseItemPayload(
            infohash,
            name,
            length,
            num_files,
            category_list,
            creation_date,
            seeders,
            leechers,
            cid,
        )
        if self.has_torrent(infohash):
            db_torrent = self.get_torrent(infohash)
            if db_torrent["name"] and db_torrent["name"] == torrent_item.name:
                self.logger.info("Conflicting names for torrent. Ignoring the response")
                continue
        else:
            self.logger.debug("Adding new torrent from search results to database")
            self.torrent_db.addOrGetTorrentID(infohash)

        # Update local database
        self.torrent_db.updateTorrent(
            infohash,
            notify=False,
            name=torrent_item.name,
            length=torrent_item.length,
            creation_date=torrent_item.creation_date,
            num_files=torrent_item.num_files,
            comment="",
        )


# Traceback (UnicodeDecodeError)
ERROR   1535980883.31             sqlitecachedb:293  (SQLiteCacheDB)  cachedb: ===MainThread===
SQL Type: <type 'unicode'>
-----
UPDATE Torrent SET comment=?,num_files=?,length=?,name=?,creation_date=? WHERE infohash='oG2Wnw6Ey+sqZ0NA9+RsGP9Ej2A='
-----
['', 1, 11814773, 'Puppy.Linux.manual.301.espa\xc3\xb1ol.pdf', 1329483575]
======
Traceback (most recent call last):
File "/var/lib/tribler/tribler/Tribler/Core/CacheDB/sqlitecachedb.py", line 284, in execute
return cur.execute(sql, args)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 27: ordinal not in range(128)
ERROR   1535980883.31                 community:397  (PopularityCommunity)  Exception occurred while handling packet!
Traceback (most recent call last):
File "/var/lib/tribler/tribler/Tribler/pyipv8/ipv8/deprecated/community.py", line 394, in on_packet
self.decode_map[data[22]](source_address, data)
File "/var/lib/tribler/tribler/Tribler/community/popularity/community.py", line 137, in on_content_info_response
self.process_torrent_search_response(cache.query, payload)
File "/var/lib/tribler/tribler/Tribler/community/popularity/community.py", line 150, in process_torrent_search_response
self.content_repository.update_from_torrent_search_results(response)
File "/var/lib/tribler/tribler/Tribler/community/popularity/repository.py", line 170, in update_from_torrent_search_results
comment='')
File "/var/lib/tribler/tribler/Tribler/Core/CacheDB/SqliteCacheDBHandler.py", line 513, in updateTorrent
self._db.update(self.table_name, where, **kw)
File "/var/lib/tribler/tribler/Tribler/Core/CacheDB/sqlitecachedb.py", line 370, in update
self.execute_write(sql, arg)
File "/var/lib/tribler/tribler/Tribler/Core/CacheDB/sqlitecachedb.py", line 326, in execute_write
self.execute(sql, args)
File "/var/lib/tribler/tribler/Tribler/pyipv8/ipv8/util.py", line 14, in helper
return blockingCallFromThread(reactor, func, *args, **kargs)
File "/var/lib/tribler/tribler/Tribler/pyipv8/ipv8/util.py", line 26, in blockingCallFromThread
return f(*args, **kwargs)
File "/var/lib/tribler/tribler/Tribler/Core/CacheDB/sqlitecachedb.py", line 295, in execute
raise msg
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 27: ordinal not in range(128)

# Fixed code
def update_from_torrent_search_results(self, search_results):
    """
    Updates the torrent database with the provided search results. It also checks for conflicting torrents, meaning
    if torrent already exists in the database, we simply ignore the search result.
    """
    for result in search_results:
        (
            infohash,
            name,
            length,
            num_files,
            category_list,
            creation_date,
            seeders,
            leechers,
            cid,
        ) = result
        name = "".join([unichr(ord(c)) for c in name])
        torrent_item = SearchResponseItemPayload(
            infohash,
            name,
            length,
            num_files,
            category_list,
            creation_date,
            seeders,
            leechers,
            cid,
        )
        if self.has_torrent(infohash):
            db_torrent = self.get_torrent(infohash)
            if db_torrent["name"] and db_torrent["name"] == torrent_item.name:
                self.logger.info("Conflicting names for torrent. Ignoring the response")
                continue
        else:
            self.logger.debug("Adding new torrent from search results to database")
            self.torrent_db.addOrGetTorrentID(infohash)

        # Update local database
        self.torrent_db.updateTorrent(
            infohash,
            notify=False,
            name=torrent_item.name,
            length=torrent_item.length,
            creation_date=torrent_item.creation_date,
            num_files=torrent_item.num_files,
            seeder=seeders,
            leecher=leechers,
            comment="",
        )