From: kaliko Date: Tue, 4 May 2021 18:37:34 +0000 (+0200) Subject: simadb: do not fetch NULL genre X-Git-Tag: 0.18.0~61 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=6e0cb104973681f2344de9c5ae4f04c62686401b;p=mpd-sima.git simadb: do not fetch NULL genre --- diff --git a/sima/lib/simadb.py b/sima/lib/simadb.py index 60844a2..07794dc 100644 --- a/sima/lib/simadb.py +++ b/sima/lib/simadb.py @@ -542,7 +542,7 @@ class SimaDB: LEFT OUTER JOIN tracks_genres ON tracks_genres.track = tracks.id LEFT OUTER JOIN artists ON tracks.artist = artists.id LEFT OUTER JOIN genres ON genres.id = tracks_genres.genre - WHERE history.last_play > ? + WHERE history.last_play > ? AND genres.name NOT NULL ORDER BY history.last_play DESC """, (date.isoformat(' '),)) genres = list() diff --git a/tests/test_simadb.py b/tests/test_simadb.py index e69c4bd..a577916 100644 --- a/tests/test_simadb.py +++ b/tests/test_simadb.py @@ -322,5 +322,16 @@ class Test_02Genre(Main): genre_hist = self.db.fetch_genres_history(limit=10) self.assertEqual([g[0] for g in genre_hist], genres[:10]) + def test_null_genres(self): + conn = self.db.get_database_connection() + genres = list() + for i in range(1, 2): # starts at 1 to ensure records are in the past + trk = Track(file=f'/foo/bar.{i}', name=f'{i}-baz', + album='foolbum', artist=f'{i}-art') + last = CURRENT - datetime.timedelta(minutes=i) + self.db.add_history(trk, date=last) + genre_hist = self.db.fetch_genres_history(limit=10) + self.assertEqual(genre_hist, []) + # VIM MODLINE # vim: ai ts=4 sw=4 sts=4 expandtab fileencoding=utf8