]> kaliko git repositories - mpd-sima.git/commitdiff
simadb: do not fetch NULL genre
authorkaliko <kaliko@azylum.org>
Tue, 4 May 2021 18:37:34 +0000 (20:37 +0200)
committerkaliko <kaliko@azylum.org>
Fri, 7 May 2021 16:24:36 +0000 (18:24 +0200)
sima/lib/simadb.py
tests/test_simadb.py

index 60844a2af38854618fed17d49d993459d6582a8a..07794dc6d24f079ea6cc5b11e234e6e02e15f4b4 100644 (file)
@@ -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()
index e69c4bda2fd1923f752aa89efbe3a01d9778997a..a57791695613b181c89b99abd45c8157c43a3b31 100644 (file)
@@ -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