Fix NoneType error when user has no subscription

g.subscription is explicitly set to None in load_user, so
g.get("subscription", {}) returns None (key exists), not {}.
Use (g.get(...) or {}) to coalesce None to an empty dict.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-02-19 23:10:56 +01:00
parent 642b529c4d
commit e80e262e25

View File

@@ -97,7 +97,7 @@ async def index():
"""Coffee analytics dashboard."""
user = g.user
stats = await get_user_stats(g.user["id"])
plan = g.get("subscription", {}).get("plan", "free")
plan = (g.get("subscription") or {}).get("plan", "free")
# Fetch all analytics data in parallel (empty lists if DB not available)
if analytics._conn is not None:
@@ -144,7 +144,7 @@ async def index():
async def countries():
"""Country comparison page."""
user = g.user
plan = g.get("subscription", {}).get("plan", "free")
plan = (g.get("subscription") or {}).get("plan", "free")
# Get available countries for coffee
all_countries = await analytics.get_top_countries(analytics.COFFEE_COMMODITY_CODE, "Production", limit=50)