--- id: c9f0d612-3f33-47ed-953d-682df63c8ed4 type: fix title: "PostgreSQL migration: get_team_by_owner returns wrong team" tags: [paper-dynasty, postgresql, migration, fix, discord-app] importance: 0.8 confidence: 0.8 created: "2026-01-31T21:50:27.501720+00:00" updated: "2026-01-31T21:50:27.501720+00:00" --- After PostgreSQL migration, get_team_by_owner() in discord-app returned the gauntlet team instead of the main team because PostgreSQL query ordering is undefined without ORDER BY. SQLite happened to return teams in a consistent order. Fix: Loop through teams and prefer the one without 'gauntlet' in the abbrev. Files: helpers.py and helpers/main.py