diff --git a/qutebrowser/completion/models/histcategory.py b/qutebrowser/completion/models/histcategory.py index 6fdab0cdb..42301c0dd 100644 --- a/qutebrowser/completion/models/histcategory.py +++ b/qutebrowser/completion/models/histcategory.py @@ -71,6 +71,10 @@ class HistoryCategory(QSqlQueryModel): 'ORDER BY last_atime DESC LIMIT :limit)', ])).run(limit=max_items).value() + if not min_atime: + # if there are no history items, min_atime may be '' (issue #2849) + return '' + return "AND last_atime >= {}".format(min_atime) def set_pattern(self, pattern): diff --git a/tests/unit/completion/test_histcategory.py b/tests/unit/completion/test_histcategory.py index a0b2b0144..db4071502 100644 --- a/tests/unit/completion/test_histcategory.py +++ b/tests/unit/completion/test_histcategory.py @@ -125,7 +125,8 @@ def test_set_pattern(pattern, before, after, model_validator, hist): ], [ ('b', 'b', '2017-06-16'), ('c', 'c', '2017-05-16'), - ]) + ]), + (1, [], []), # issue 2849 (crash with empty history) ]) def test_sorting(max_items, before, after, model_validator, hist, config_stub): """Validate the filtering and sorting results of set_pattern."""