Fix adventures list 500 on Postgres (GROUP BY)
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TEpWMjnfPqzZ13nPMoGhs5
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
c96b8cdf2f
commit
0971d3feda
@@ -35,7 +35,11 @@ def list_adventures(db: Session = Depends(get_db), user: models.User = CurrentUs
|
|||||||
.outerjoin(models.Action)
|
.outerjoin(models.Action)
|
||||||
.outerjoin(models.Scenario, models.Adventure.scenario_id == models.Scenario.id)
|
.outerjoin(models.Scenario, models.Adventure.scenario_id == models.Scenario.id)
|
||||||
.filter(models.Adventure.user_id == user.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())
|
.order_by(models.Adventure.updated_at.desc())
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user