From 0971d3fedafed3f4664702eeea6b2ec8813d92ed Mon Sep 17 00:00:00 2001 From: parththakkar106 Date: Mon, 20 Jul 2026 16:41:51 +0530 Subject: [PATCH] Fix adventures list 500 on Postgres (GROUP BY) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit list_adventures selected Scenario.title while grouping only by Adventure.id. SQLite tolerates selecting an ungrouped column, so it worked locally, but Postgres (Neon) rejects it — the adventures list endpoint 500'd on the live deploy, so saved adventures could not be listed or resumed. Add Scenario.title to the GROUP BY. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01TEpWMjnfPqzZ13nPMoGhs5 --- backend/app/routers/adventures.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/routers/adventures.py b/backend/app/routers/adventures.py index 9a96b1f..71a64da 100644 --- a/backend/app/routers/adventures.py +++ b/backend/app/routers/adventures.py @@ -35,7 +35,11 @@ def list_adventures(db: Session = Depends(get_db), user: models.User = CurrentUs .outerjoin(models.Action) .outerjoin(models.Scenario, models.Adventure.scenario_id == models.Scenario.id) .filter(models.Adventure.user_id == user.id) - .group_by(models.Adventure.id) + # Group by both PKs: Postgres requires every selected column to be + # grouped or aggregated. Adventure.* rides on its own grouped PK, but + # Scenario.title comes from a joined table and must be listed too + # (SQLite is lax here; Postgres rejects it). + .group_by(models.Adventure.id, models.Scenario.title) .order_by(models.Adventure.updated_at.desc()) .all() )