diff --git a/database/video_database.py b/database/video_database.py index d8224198..dec191f8 100644 --- a/database/video_database.py +++ b/database/video_database.py @@ -2044,8 +2044,10 @@ class VideoDatabase: if sort == "added": # opt-in: explicit follows (have a date) newest-first items.sort(key=lambda it: (it.get("date_added") or ""), reverse=True) else: # "default" / "title": alphabetical by name — a manual follow is no more - # special than an auto-added airing show, so they sort together A–Z - items.sort(key=lambda it: (it.get("sort_title") or it.get("title") or "").lower()) + # special than an auto-added airing show, so they sort together A–Z. + # .strip() guards against dirty titles (e.g. a leading space from the + # scan, which would otherwise sort before 'a'). + items.sort(key=lambda it: (it.get("sort_title") or it.get("title") or "").strip().lower()) total = len(items) total_pages = max(1, (total + limit - 1) // limit) page = min(page, total_pages) diff --git a/tests/test_video_database.py b/tests/test_video_database.py index eb34007c..17043371 100644 --- a/tests/test_video_database.py +++ b/tests/test_video_database.py @@ -851,11 +851,13 @@ def test_query_watchlist_default_sort_is_alphabetical(db): db.add_to_watchlist("show", 1, "Welcome to Widows Bay") db.add_to_watchlist("show", 2, "From") db.add_to_watchlist("show", 3, "Andor") - titles = [it["title"] for it in db.query_watchlist("show")["items"]] - assert titles == ["Andor", "From", "Welcome to Widows Bay"] + db.add_to_watchlist("show", 4, " Holy Marvels with Dennis Quaid") # dirty leading space + titles = [it["title"].strip() for it in db.query_watchlist("show")["items"]] + # a leading-space title must NOT jump the queue — sorts under H + assert titles == ["Andor", "From", "Holy Marvels with Dennis Quaid", "Welcome to Widows Bay"] # 'added' is still available opt-in (newest first) - added = [it["title"] for it in db.query_watchlist("show", sort="added")["items"]] - assert added[0] == "Andor" # most recently added + added = [it["title"].strip() for it in db.query_watchlist("show", sort="added")["items"]] + assert added[0] == "Holy Marvels with Dennis Quaid" # most recently added # ── wishlist (movies + episodes; show/season are bulk ops over episodes) ──────