# Buggy code
def set_pattern(self, pattern):
    """Set the pattern on the underlying model."""
    if not self.model():
        return
    self.pattern = pattern
    with debug.log_time(log.completion, "Set pattern {}".format(pattern)):
        self.model().set_pattern(pattern)
        self._maybe_update_geometry()
        self._maybe_show()


# Traceback (KeyError)
19:03:56 DEBUG    commands   command:run:524 Calling qutebrowser.completion.completionwidget.CompletionView.completion_item_del(<qutebrowser.completion.completionwidget.CompletionView>)
19:03:56 DEBUG    completion urlmodel:_delete_history:34 Deleting history entry None
19:03:56 DEBUG    sql        sql:__init__:80 Preparing SQL query: "DELETE FROM History where url = :val"
19:03:56 DEBUG    sql        sql:run:99 Running SQL query: "DELETE FROM History where url = :val"
19:03:56 DEBUG    sql        sql:run:102 query bindings: {':val': None}
19:03:56 ERROR    misc       crashsignal:exception_hook:205 Uncaught exception
Traceback (most recent call last):
File "/home/florian/proj/qutebrowser/git/qutebrowser/app.py", line 889, in eventFilter
return handler(event)
File "/home/florian/proj/qutebrowser/git/qutebrowser/app.py", line 849, in _handle_key_event
return man.eventFilter(event)
File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeman.py", line 337, in eventFilter
return self._eventFilter_keypress(event)
File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/modeman.py", line 168, in _eventFilter_keypress
handled = parser.handle(event)
File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/basekeyparser.py", line 307, in handle
handled = self._handle_special_key(e)
File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/basekeyparser.py", line 136, in _handle_special_key
self.execute(cmdstr, self.Type.special, count)
File "/home/florian/proj/qutebrowser/git/qutebrowser/keyinput/keyparser.py", line 44, in execute
self._commandrunner.run(cmdstr, count)
File "/home/florian/proj/qutebrowser/git/qutebrowser/commands/runners.py", line 275, in run
result.cmd.run(self._win_id, args, count=count)
File "/home/florian/proj/qutebrowser/git/qutebrowser/commands/command.py", line 525, in run
self.handler(*posargs, **kwargs)
File "/home/florian/proj/qutebrowser/git/qutebrowser/completion/completionwidget.py", line 376, in completion_item_del
self.model().delete_cur_item(index)
File "/home/florian/proj/qutebrowser/git/qutebrowser/completion/models/completionmodel.py", line 223, in delete_cur_item
cat.delete_cur_item(cat.index(index.row(), 0))
File "/home/florian/proj/qutebrowser/git/qutebrowser/completion/models/histcategory.py", line 99, in delete_cur_item
self.delete_func(data)
File "/home/florian/proj/qutebrowser/git/qutebrowser/completion/models/urlmodel.py", line 36, in _delete_history
hist.delete_url(urlstr)
File "/home/florian/proj/qutebrowser/git/qutebrowser/browser/history.py", line 126, in delete_url
self.delete('url', url)
File "/home/florian/proj/qutebrowser/git/qutebrowser/misc/sql.py", line 196, in delete
raise KeyError('No row with {} = "{}"'.format(field, value))
KeyError: 'No row with url = "None"'

# Fixed code
def set_pattern(self, pattern):
    """Set the pattern on the underlying model."""
    if not self.model():
        return
    self.pattern = pattern
    with debug.log_time(log.completion, "Set pattern {}".format(pattern)):
        self.model().set_pattern(pattern)
        self.selectionModel().clear()
        self._maybe_update_geometry()
        self._maybe_show()