From 10255296d58a7bd73f26f5ad446f581db2afe5f8 Mon Sep 17 00:00:00 2001 From: Oliver Falk Date: Wed, 24 Sep 2025 09:37:26 +0200 Subject: [PATCH] Fix SQLite AVG() type conversion in photo size stats - Convert avg_size_bytes to float to handle SQLite returning string values - Fixes TypeError: '>' not supported between instances of 'str' and 'int' - Ensures photo size statistics work correctly across different database backends - All 5 stats tests pass successfully The issue occurred because SQLite's AVG() function can return string representations of numbers in some cases, causing type comparison errors in tests. --- ivatar/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ivatar/views.py b/ivatar/views.py index 997a824..45f6bf9 100644 --- a/ivatar/views.py +++ b/ivatar/views.py @@ -698,6 +698,8 @@ class StatsView(TemplateView, JsonResponse): if result and result[0] > 0: photo_count, avg_size_bytes = result + # Convert to float in case SQLite returns string + avg_size_bytes = float(avg_size_bytes) if avg_size_bytes else 0 avg_size_kb = round(avg_size_bytes / 1024, 2) if avg_size_bytes else 0 avg_size_mb = ( round(avg_size_bytes / (1024 * 1024), 2) if avg_size_bytes else 0