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.
This commit is contained in:
Oliver Falk
2025-09-24 09:37:26 +02:00
parent 213e0cb213
commit 10255296d5

View File

@@ -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