chunned / databass

Databass is a music diary to track the releases you listen to and how you feel about them.
1 stars 0 forks source link

Error on fresh install: `TypeError: type NoneType doesn't define __round__ method` #9

Open IgnisDa opened 3 weeks ago

IgnisDa commented 3 weeks ago

Hi, I am the author of Ryot. You mentioned this project in the issue tracker for Music tracking. I tried to run the application using the instructions but it does not work.

Here is the error:

image

chunned commented 3 weeks ago

Hi, thanks for checking out my project!

This should now be fixed - I had forgotten to add some checks for when the database is empty. Pull the new Docker image and you should be good to go.

I see you did so already in your screenshot, but I also updated the deployment instructions to mention that you need to touch music.db prior to launching the Docker compose, otherwise it'll attempt to mount as a directory.

Let me know if you run into any other issues - this is my first real project, and I'm not a developer by trade, so I'm sure there will be some more things like this that I've forgotten about.

IgnisDa commented 3 weeks ago
diff --git a/api.py b/api.py
index 5c05a15..b347639 100644
--- a/api.py
+++ b/api.py
@@ -2,6 +2,9 @@ import json
 import requests
 from datetime import datetime
 import os
+from dotenv import load_dotenv
+
+load_dotenv()

 header = {"Accept": "application/json", "User-Agent": "databass/0.2 (https://github.com/chunned/databass)"}

@@ -9,6 +12,10 @@ header = {"Accept": "application/json", "User-Agent": "databass/0.2 (https://git
 DISCOGS_KEY = os.getenv("DISCOGS_KEY")
 DISCOGS_SECRET = os.getenv("DISCOGS_SECRET")

+if not DISCOGS_KEY or not DISCOGS_SECRET:
+    print("Error: Discogs API keys not found. Please set DISCOGS_KEY and DISCOGS_SECRET in your environment.")
+    exit(1)
+

 def pick_release(release, artist, rating, year, genre, tags):
     # Accepts search parameters and returns a list of matching releases, which the user must select from
diff --git a/db.py b/db.py
index f95dcf6..816b03e 100644
--- a/db.py
+++ b/db.py
@@ -53,8 +53,13 @@ def create_tables(cur):
     CREATE TABLE IF NOT EXISTS artist(
         id INTEGER PRIMARY KEY AUTOINCREMENT,
         mbid TEXT UNIQUE,
-        name TEXT
-    )
+        name TEXT,
+        country TEXT,
+        type TEXT,
+        begin_date TEXT,
+        end_date TEXT,
+        image TEXT
+    )
     """)

     # Create LABEL table
@@ -62,8 +67,13 @@ def create_tables(cur):
     CREATE TABLE IF NOT EXISTS label(
         id INTEGER PRIMARY KEY,
         mbid TEXT UNIQUE,
-        name TEXT
-    )
+        name TEXT,
+        country TEXT,
+        type TEXT,
+        begin_date TEXT,
+        end_date TEXT,
+        image TEXT
+    )
     """)

@@ -131,10 +141,15 @@ def get_stats(cur, con):
     stats["total_artists"] = cur.fetchone()[0]

     cur.execute("SELECT AVG(rating) FROM release")
-    stats["average_rating"] = round(cur.fetchone()[0], 2)
+    average_rating = cur.fetchone()[0]
+    if average_rating is None:
+        average_rating = 0
+    stats["average_rating"] = round(average_rating, 2)

     cur.execute("SELECT AVG(runtime) FROM release")
     runtime_ms = cur.fetchone()[0]
+    if runtime_ms is None:
+        runtime_ms = 0
     stats["average_runtime"] = round((runtime_ms / 60000), 2)

     cur.execute("SELECT SUM(runtime) FROM release")
@@ -157,10 +172,10 @@ def get_stats(cur, con):

     # most frequent labels
     most_frequent_labels_query = """
-    SELECT label.name, COUNT(*) as Count
-    FROM label
-    JOIN release ON release.label_id = label.id
-    GROUP BY label.name
+    SELECT label.name, COUNT(*) as Count
+    FROM label
+    JOIN release ON release.label_id = label.id
+    GROUP BY label.name
     ORDER BY Count DESC
     LIMIT 5;
     """
@@ -170,12 +185,12 @@ def get_stats(cur, con):

     # highest rated labels
     top_label_query = """
-    SELECT label.name, ROUND(AVG(release.rating), 2) AS Average_Rating, COUNT(release.label_id) as Release_Count
-    FROM label
+    SELECT label.name, ROUND(AVG(release.rating), 2) AS Average_Rating, COUNT(release.label_id) as Release_Count
+    FROM label
     JOIN release ON release.label_id = label.id
     WHERE label.name IS NOT "none" AND label.name IS NOT "[no label]"
     GROUP BY label.name
-    HAVING Release_Count != 1
+    HAVING Release_Count != 1
     ORDER BY Average_Rating DESC
     LIMIT 5;"""
     cur.execute(top_label_query)
@@ -184,11 +199,11 @@ def get_stats(cur, con):

     # highest rated artists
     top_artist_query = """
-    SELECT artist.name, ROUND(AVG(release.rating), 2) AS Average_Rating, COUNT(release.artist_id) as Release_Count
+    SELECT artist.name, ROUND(AVG(release.rating), 2) AS Average_Rating, COUNT(release.artist_id) as Release_Count
     FROM artist
     JOIN release ON release.artist_id = artist.id
     GROUP BY artist.name
-    HAVING Release_Count != 1
+    HAVING Release_Count != 1
     ORDER BY Average_Rating DESC
     LIMIT 5;"""
     cur.execute(top_artist_query)

I had to make all these changes to your project to get it running locally. Some of them are just whitespace changes made by the formatter so those can be ignored.

chunned commented 3 weeks ago

Thank you very much for spotting these!

I fixed the two stats errors earlier in this commit - reopening this so I don't forget to add the other fixes tomorrow