From cfb14fce5598523da29ae1180902bbe164771279 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 4 May 2023 01:12:40 +0300 Subject: [PATCH] fix issue with multiple blackjack games --- files/helpers/twentyone.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/files/helpers/twentyone.py b/files/helpers/twentyone.py index 8bcf87788..5fc00976c 100644 --- a/files/helpers/twentyone.py +++ b/files/helpers/twentyone.py @@ -8,6 +8,8 @@ from flask import g from files.classes.casino_game import CasinoGame from files.helpers.casino import distribute_wager_badges +from sqlalchemy.orm.exc import MultipleResultsFound + class BlackjackStatus(str, Enum): PLAYING = "PLAYING" STAYED = "STAYED" @@ -69,11 +71,20 @@ def build_casino_game(gambler, wager, currency): def get_active_twentyone_game(gambler): - return g.db.query(CasinoGame).filter( + try: + return g.db.query(CasinoGame).filter( CasinoGame.active == True, CasinoGame.kind == 'blackjack', - CasinoGame.user_id == gambler.id).first() - + CasinoGame.user_id == gambler.id).one_or_none() + except MultipleResultsFound: + games = g.db.query(CasinoGame).filter( + CasinoGame.active == True, + CasinoGame.kind == 'blackjack', + CasinoGame.user_id == gambler.id).all() + for game in games: + g.db.delete(game) + g.db.commit() + return None def get_active_twentyone_game_state(gambler): active_game = get_active_twentyone_game(gambler)