# Buggy code
async def check_random_tracker(self):
    """
    Calling this method will fetch a random tracker from the database, select some torrents that have this
    tracker, and perform a request to these trackers.
    """
    tracker_url = self.get_valid_next_tracker_for_auto_check()
    if tracker_url is None:
        self._logger.warning("No tracker to select from, skip")
        return

    self._logger.debug("Start selecting torrents on tracker %s.", tracker_url)

    # get the torrents that should be checked
    with db_session:
        tracker = self.tribler_session.mds.TrackerState.get(url=tracker_url)
        if not tracker:
            return
        dynamic_interval = TORRENT_CHECK_RETRY_INTERVAL * (2**tracker.failures)
        torrents = select(
            ts
            for ts in tracker.torrents
            if ts.last_check + dynamic_interval < int(time.time())
        )
        infohashes = [t.infohash for t in torrents[:MAX_TORRENTS_CHECKED_PER_SESSION]]

    if len(infohashes) == 0:
        # We have no torrent to recheck for this tracker. Still update the last_check for this tracker.
        self._logger.info("No torrent to check for tracker %s", tracker_url)
        self.update_tracker_info(tracker_url, True)
        return

    try:
        session = self._create_session_for_request(tracker_url, timeout=30)
    except MalformedTrackerURLException as e:
        # Remove the tracker from the database
        self.remove_tracker(tracker_url)
        self._logger.error(e)
        return

    # We shuffle the list so that different infohashes are checked on subsequent scrape requests if the total
    # number of infohashes exceeds the maximum number of infohashes we check.
    random.shuffle(infohashes)
    for infohash in infohashes:
        session.add_infohash(infohash)

    self._logger.info(
        "Selected %d new torrents to check on tracker: %s", len(infohashes), tracker_url
    )
    try:
        await self.connect_to_tracker(session)
    except:
        pass


# Traceback (RuntimeError)
[PID:19277] 2020-02-19 20:12:31,372 - ERROR <session:369> Session.unhandled_error_observer(): Got unhandled error: Python int too large to convert to SQLite INTEGER
File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/home/vader/src/TRIBLER/Tribler/src/pyipv8/ipv8/taskmanager.py", line 104, in done_cb
future.result()
File "/home/vader/src/TRIBLER/Tribler/src/pyipv8/ipv8/taskmanager.py", line 13, in interval_runner
await task(*args)
File "/home/vader/src/TRIBLER/Tribler/src/tribler-core/tribler_core/modules/torrent_checker/torrent_checker.py", line 115, in check_random_tracker
infohashes = [t.infohash for t in torrents[:MAX_TORRENTS_CHECKED_PER_SESSION]]
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/orm/core.py", line 6162, in __getitem__
return query._fetch(limit=stop-start, offset=start)
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/orm/core.py", line 6164, in _fetch
return QueryResult(query, limit, offset, lazy=lazy)
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/orm/core.py", line 6271, in __init__
self._items = None if lazy else self._query._actual_fetch(limit, offset)
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/orm/core.py", line 5804, in _actual_fetch
cursor = database._exec_sql(sql, arguments)
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/orm/core.py", line 945, in _exec_sql
connection = cache.reconnect(e)
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/orm/core.py", line 1779, in reconnect
if not provider.should_reconnect(exc): reraise(*sys.exc_info())
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/utils/utils.py", line 95, in reraise
try: raise exc.with_traceback(tb)
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/orm/core.py", line 943, in _exec_sql
try: new_id = provider.execute(cursor, sql, arguments, returning_id)
File "<string>", line 2, in execute
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/orm/dbapiprovider.py", line 53, in wrap_dbapi_exceptions
try: return func(provider, *args, **kwargs)
File "/home/vader/src/TRIBLER/py37venv2/lib/python3.7/site-packages/pony/orm/dbapiprovider.py", line 270, in execute
else: cursor.execute(sql, arguments)
[PID:19220] 2020-02-19 20:12:31,395 - ERROR <tribler_window:104> root.on_exception(): Traceback (most recent call last):
File "/home/vader/src/TRIBLER/Tribler/src/tribler-gui/tribler_gui/event_request_manager.py", line 114, in on_read_data
raise RuntimeError(json_dict["event"]["text"])
RuntimeError: Python int too large to convert to SQLite INTEGER

# Fixed code
async def check_random_tracker(self):
    """
    Calling this method will fetch a random tracker from the database, select some torrents that have this
    tracker, and perform a request to these trackers.
    """
    tracker_url = self.get_valid_next_tracker_for_auto_check()
    if tracker_url is None:
        self._logger.warning("No tracker to select from, skip")
        return

    self._logger.debug("Start selecting torrents on tracker %s.", tracker_url)

    # get the torrents that should be checked
    with db_session:
        tracker = self.tribler_session.mds.TrackerState.get(url=tracker_url)
        if not tracker:
            return
        dynamic_interval = TORRENT_CHECK_RETRY_INTERVAL * (2**tracker.failures)
        # FIXME: this is a really dumb fix for update_tracker_info not being called in some cases
        if tracker.failures >= MAX_TRACKER_FAILURES:
            tracker.alive = False
            return
        torrents = select(
            ts
            for ts in tracker.torrents
            if ts.last_check + dynamic_interval < int(time.time())
        )
        infohashes = [t.infohash for t in torrents[:MAX_TORRENTS_CHECKED_PER_SESSION]]

    if len(infohashes) == 0:
        # We have no torrent to recheck for this tracker. Still update the last_check for this tracker.
        self._logger.info("No torrent to check for tracker %s", tracker_url)
        self.update_tracker_info(tracker_url, True)
        return

    try:
        session = self._create_session_for_request(tracker_url, timeout=30)
    except MalformedTrackerURLException as e:
        # Remove the tracker from the database
        self.remove_tracker(tracker_url)
        self._logger.error(e)
        return

    # We shuffle the list so that different infohashes are checked on subsequent scrape requests if the total
    # number of infohashes exceeds the maximum number of infohashes we check.
    random.shuffle(infohashes)
    for infohash in infohashes:
        session.add_infohash(infohash)

    self._logger.info(
        "Selected %d new torrents to check on tracker: %s", len(infohashes), tracker_url
    )
    try:
        await self.connect_to_tracker(session)
    except:
        pass