@@ -68,6 +68,23 @@ def test_keeps_most_recent_watched_at_across_rows(self):
6868 last_per_show , last_watched_at = _group_last_watched (rows )
6969 self .assertEqual (last_watched_at [1 ], newer )
7070
71+ def test_null_season_row_is_skipped_not_used_as_last_watched (self ):
72+ # Regression for #132: a faulty history entry with a NULL season (e.g.
73+ # a pre-fix Season-0 scrobble) must not become a show's "furthest
74+ # watched" position — get_next_up would later pass that None straight
75+ # into an int comparison and crash the whole endpoint.
76+ rows = [
77+ (1 , None , 3 , datetime (2026 , 1 , 2 , tzinfo = timezone .utc )),
78+ (1 , 1 , 5 , datetime (2026 , 1 , 1 , tzinfo = timezone .utc )),
79+ ]
80+ last_per_show , last_watched_at = _group_last_watched (rows )
81+ self .assertEqual (last_per_show [1 ], (1 , 5 ))
82+
83+ def test_show_with_only_null_season_rows_has_no_entry (self ):
84+ rows = [(1 , None , 1 , None ), (1 , None , 2 , None )]
85+ last_per_show , last_watched_at = _group_last_watched (rows )
86+ self .assertNotIn (1 , last_per_show )
87+
7188
7289class HasAiredTests (unittest .TestCase ):
7390 """Regression tests for #104: Next Up must not suggest an episode before
0 commit comments