From b5b041c889e4b067ad7e6b6ca5b4d10196356925 Mon Sep 17 00:00:00 2001 From: Daniel Nagel Date: Fri, 29 May 2026 08:20:09 +0000 Subject: [PATCH 1/4] error handling join_league() --- data/data_api.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/data/data_api.py b/data/data_api.py index cb88fb5..1d4dd52 100644 --- a/data/data_api.py +++ b/data/data_api.py @@ -250,12 +250,16 @@ def join_league(player_id, gamesystem_id): INSERT INTO player_game_statistic (player_id, gamesystem_id) VALUES (%s, %s) """ - logger.log(f"{get_player_name(player_id)} joined {gamesystem_id}") - cursor.execute(query, (player_id, gamesystem_id)) - connection.commit() - - cursor.close() - connection.close() + try: + cursor.execute(query, (player_id, gamesystem_id)) + connection.commit() + logger.log(f"{get_player_name(player_id)} joined {gamesystem_id}") + except mariadb.Error as e: + logger.log(f"FEHLER beim Insert: {e}") # WICHTIG! + raise + finally: + cursor.close() + connection.close() # ----------------------------------------------------- -- 2.43.0 From 049089cb5fdc11f791c3a9b99b9c8f73f4a8521b Mon Sep 17 00:00:00 2001 From: Daniel Nagel Date: Fri, 29 May 2026 08:23:07 +0000 Subject: [PATCH 2/4] WIP Fehler --- data/data_api.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/data/data_api.py b/data/data_api.py index 1d4dd52..d20e1f0 100644 --- a/data/data_api.py +++ b/data/data_api.py @@ -247,16 +247,15 @@ def join_league(player_id, gamesystem_id): cursor = connection.cursor() query = """ - INSERT INTO player_game_statistic (player_id, gamesystem_id) - VALUES (%s, %s) + INSERT INTO player_game_statistic (player_id, gamesystem_id, season_id) + VALUES (%s, %s, 1) # Ich habe season_id mal testweise auf 1 gesetzt! """ try: cursor.execute(query, (player_id, gamesystem_id)) connection.commit() - logger.log(f"{get_player_name(player_id)} joined {gamesystem_id}") - except mariadb.Error as e: - logger.log(f"FEHLER beim Insert: {e}") # WICHTIG! - raise + logger.log(f"Erfolg: {player_id} joined {gamesystem_id}") + except Exception as e: + print(f"DATENBANK-FEHLER: {e}") finally: cursor.close() connection.close() -- 2.43.0 From 0b42c081fe269be8e99f7810f3927eecff4cc0c0 Mon Sep 17 00:00:00 2001 From: Daniel Nagel Date: Fri, 29 May 2026 09:23:28 +0000 Subject: [PATCH 3/4] =?UTF-8?q?Error=20handling=20f=C3=BCr=20join=5Fleague?= =?UTF-8?q?=20und=20aktive=20season=20abfrage.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/data_api.py | 60 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/data/data_api.py b/data/data_api.py index d20e1f0..8a537a5 100644 --- a/data/data_api.py +++ b/data/data_api.py @@ -242,23 +242,59 @@ def get_player_rank(player_id, system_id): return row['rank'] return None + + def join_league(player_id, gamesystem_id): + try: + # 1. Die richtige Season für dieses System holen + season_id = get_current_season_id(gamesystem_id) + + connection = db_connection() + cursor = connection.cursor() + + query = """ + INSERT INTO player_game_statistic + (player_id, gamesystem_id, season_id) + VALUES (%s, %s, %s) + """ + cursor.execute(query, (player_id, gamesystem_id, season_id)) + connection.commit() + + logger.log(f"Erfolg: Spieler {player_id} joined System {gamesystem_id} in Season {season_id}") + + except Exception as e: + logger.log(f"FEHLER beim Beitreten: {e}") + raise + finally: + # Hier ist ein kleiner Check, ob die connection überhaupt existiert + if 'connection' in locals() and connection: + cursor.close() + connection.close() + + + +def get_current_season_id(gamesystem_id): connection = db_connection() - cursor = connection.cursor() + cursor = connection.cursor(dictionary=True) query = """ - INSERT INTO player_game_statistic (player_id, gamesystem_id, season_id) - VALUES (%s, %s, 1) # Ich habe season_id mal testweise auf 1 gesetzt! + SELECT id FROM seasons + WHERE gamesystem_id = %s + ORDER BY start_date DESC + LIMIT 1 """ - try: - cursor.execute(query, (player_id, gamesystem_id)) - connection.commit() - logger.log(f"Erfolg: {player_id} joined {gamesystem_id}") - except Exception as e: - print(f"DATENBANK-FEHLER: {e}") - finally: - cursor.close() - connection.close() + cursor.execute(query, (gamesystem_id,)) + result = cursor.fetchone() + + cursor.close() + connection.close() + + if result: + return result['id'] + else: + # Hier wissen wir jetzt genau, welches Spielsystem keine Saison hat + raise RuntimeError(f"Keine Saison für Spielsystem {gamesystem_id} gefunden!") + # ----------------------------------------------------- -- 2.43.0 From b1cc40061198a0d3b3e5d3081d872cfe326e174d Mon Sep 17 00:00:00 2001 From: Daniel Nagel Date: Fri, 29 May 2026 09:26:21 +0000 Subject: [PATCH 4/4] Refractor --- data/data_api.py | 2 +- gui/main_gui.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/data/data_api.py b/data/data_api.py index 8a537a5..fdb1ec4 100644 --- a/data/data_api.py +++ b/data/data_api.py @@ -293,7 +293,7 @@ def get_current_season_id(gamesystem_id): return result['id'] else: # Hier wissen wir jetzt genau, welches Spielsystem keine Saison hat - raise RuntimeError(f"Keine Saison für Spielsystem {gamesystem_id} gefunden!") + raise RuntimeError(f"Keine Saison für {gamesystem_id} gefunden!") diff --git a/gui/main_gui.py b/gui/main_gui.py index 19052c4..bdb841e 100644 --- a/gui/main_gui.py +++ b/gui/main_gui.py @@ -244,8 +244,6 @@ def setup_routes(admin_discord_id): ui.label(text=f"MMR: {stat['mmr']}").classes("text-lg font-bold text-accenttext") ui.label(text=f"Spiele: {stat['games_in_system']}").classes("text-lg font-bold text-accenttext") - - # --------------------------- # Match Historie # --------------------------- -- 2.43.0