# Buggy code
def add_tracker(self, tracker_url):
    """
    Adds a new tracker into the tracker info dict and the database.
    :param tracker_url: The new tracker URL to be added.
    """
    sanitized_tracker_url = get_uniformed_tracker_url(tracker_url)
    if sanitized_tracker_url is None:
        self._logger.warn("skip invalid tracker: %s", repr(tracker_url))
        return

    if sanitized_tracker_url in self._tracker_dict:
        self._logger.debug("skip existing tracker: %s", repr(tracker_url))
        return

    # add the tracker into dict and database
    tracker_info = {"last_check": 0, "failures": 0, "is_alive": True}

    # insert into database
    sql_stmt = """INSERT INTO TrackerInfo(tracker, last_check, failures, is_alive) VALUES(?,?,?,?);
                       SELECT tracker_id FROM TrackerInfo WHERE tracker = ?;
                    """
    value_tuple = (
        sanitized_tracker_url,
        tracker_info["last_check"],
        tracker_info["failures"],
        tracker_info["is_alive"],
        sanitized_tracker_url,
    )
    (tracker_id,) = self._session.sqlite_db.execute(sql_stmt, value_tuple).next()

    # update dict
    tracker_info["id"] = tracker_id
    self._tracker_dict[sanitized_tracker_url] = tracker_info
    self._tracker_id_to_url_dict[tracker_id] = sanitized_tracker_url


# Traceback (AssertionError)
Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')
Stacktrace

Traceback (most recent call last):
File "c:\python27\lib\unittest\case.py", line 329, in run
testMethod()
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\test_as_server.py", line 58, in check
result = fun(*argv, **kwargs)
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\Core\Upgrade\test_config_upgrade_70_71.py", line 33, in test_read_test_libtribler_conf
self.assertEqual(result_config.get_anon_proxy_settings(), (2, ("127.0.0.1", [5, 4, 3, 2, 1]), ''))
File "c:\python27\lib\unittest\case.py", line 513, in assertEqual
assertion_func(first, second, msg=msg)
File "c:\python27\lib\unittest\case.py", line 753, in assertTupleEqual
self.assertSequenceEqual(tuple1, tuple2, msg, seq_type=tuple)
File "c:\python27\lib\unittest\case.py", line 724, in assertSequenceEqual
self.fail(msg)
File "c:\python27\lib\unittest\case.py", line 410, in fail
raise self.failureException(msg)
AssertionError: Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')

# Fixed code
def add_tracker(self, tracker_url):
    """
    Adds a new tracker into the tracker info dict and the database.
    :param tracker_url: The new tracker URL to be added.
    """
    sanitized_tracker_url = get_uniformed_tracker_url(tracker_url)
    if sanitized_tracker_url is None:
        self._logger.warn("skip invalid tracker: %s", repr(tracker_url))
        return

    sql_stmt = "SELECT COUNT() FROM TrackerInfo WHERE tracker = ?"
    num = self._session.sqlite_db.execute(sql_stmt, (sanitized_tracker_url,)).next()[0]
    if num > 0:
        self._logger.debug("skip existing tracker: %s", repr(tracker_url))
        return

    # add the tracker into dict and database
    tracker_info = {"last_check": 0, "failures": 0, "is_alive": True}

    # insert into database
    sql_stmt = """INSERT INTO TrackerInfo(tracker, last_check, failures, is_alive) VALUES(?,?,?,?);
                       SELECT tracker_id FROM TrackerInfo WHERE tracker = ?;
                    """
    value_tuple = (
        sanitized_tracker_url,
        tracker_info["last_check"],
        tracker_info["failures"],
        tracker_info["is_alive"],
        sanitized_tracker_url,
    )
    self._session.sqlite_db.execute(sql_stmt, value_tuple).next()