# Buggy code
def add_url(self, url, title="", *, redirect=False, atime=None):
    """Called via add_from_tab when a URL should be added to the history.

    Args:
        url: A url (as QUrl) to add to the history.
        redirect: Whether the entry was redirected to another URL
                  (hidden in completion)
        atime: Override the atime used to add the entry
    """
    if not url.isValid():
        log.misc.warning("Ignoring invalid URL being added to history")
        return

    if "no-sql-history" in objreg.get("args").debug_flags:
        return

    atime = int(atime) if (atime is not None) else int(time.time())
    self.insert(
        {
            "url": self._format_url(url),
            "title": title,
            "atime": atime,
            "redirect": redirect,
        }
    )
    if not redirect:
        self.completion.insert(
            {
                "url": self._format_completion_url(url),
                "title": title,
                "last_atime": atime,
            },
            replace=True,
        )


# Traceback (qutebrowser.misc.sql.SqlException)
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "SELECT EXISTS(SELECT * FROM History WHERE url = :val)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':val': 'https://wiki.archlinux.org/index.php/ArchWiki:Privacy_policy'}
20:42:34 DEBUG    sql        debug:__exit__:264 Historycontains took 0.000158 seconds.
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "SELECT EXISTS(SELECT * FROM History WHERE url = :val)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':val': 'https://wiki.archlinux.org/index.php/ArchWiki:About'}
20:42:34 DEBUG    sql        debug:__exit__:264 Historycontains took 0.000111 seconds.
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "SELECT EXISTS(SELECT * FROM History WHERE url = :val)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':val': 'https://wiki.archlinux.org/index.php/ArchWiki:General_disclaimer'}
20:42:34 DEBUG    sql        debug:__exit__:264 Historycontains took 9.4e-05 seconds.
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "SELECT EXISTS(SELECT * FROM History WHERE url = :val)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':val': 'https://wiki.archlinux.org/index.php?title=Tor&amp;mobileaction=toggle_view_mobile'}
20:42:34 DEBUG    sql        debug:__exit__:264 Historycontains took 0.000114 seconds.
20:42:34 DEBUG    sql        sql:__init__:80 Preparing SQL query: "INSERT INTO History (url, title, atime, redirect) values(:url, :title, :atime, :redirect)"
20:42:34 DEBUG    sql        sql:run:99 Running SQL query: "INSERT INTO History (url, title, atime, redirect) values(:url, :title, :atime, :redirect)"
20:42:34 DEBUG    sql        sql:run:102 query bindings: {':atime': 1501461754, ':redirect': False, ':title': 'Tor - ArchWiki', ':url': 'https://wiki.archlinux.org/index.php/Tor#Usage'}
20:42:34 ERROR    misc       crashsignal:exception_hook:210 Uncaught exception
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/history.py", line 144, in add_from_tab
self.add_url(url, title)
File "/usr/lib/python3.6/site-packages/qutebrowser/browser/history.py", line 166, in add_url
'redirect': redirect})
File "/usr/lib/python3.6/site-packages/qutebrowser/misc/sql.py", line 214, in insert
q.run(**values)
File "/usr/lib/python3.6/site-packages/qutebrowser/misc/sql.py", line 105, in run
self.lastQuery(), self.lastError().text()))
qutebrowser.misc.sql.SqlException: Failed to exec query "INSERT INTO History (url, title, atime, redirect) values(:url, :title, :atime, :redirect)": "database is locked Unable to fetch row"

# Fixed code
def add_url(self, url, title="", *, redirect=False, atime=None):
    """Called via add_from_tab when a URL should be added to the history.

    Args:
        url: A url (as QUrl) to add to the history.
        redirect: Whether the entry was redirected to another URL
                  (hidden in completion)
        atime: Override the atime used to add the entry
    """
    if not url.isValid():
        log.misc.warning("Ignoring invalid URL being added to history")
        return

    if "no-sql-history" in objreg.get("args").debug_flags:
        return

    atime = int(atime) if (atime is not None) else int(time.time())

    try:
        self.insert(
            {
                "url": self._format_url(url),
                "title": title,
                "atime": atime,
                "redirect": redirect,
            }
        )
        if not redirect:
            self.completion.insert(
                {
                    "url": self._format_completion_url(url),
                    "title": title,
                    "last_atime": atime,
                },
                replace=True,
            )
    except sql.SqlError as e:
        if e.environmental:
            message.error("Failed to write history: {}".format(e.text()))
        else:
            raise