From 3da917966d4f9d46ede749221664a4c059fd433e Mon Sep 17 00:00:00 2001 From: Samuel Cattini-Schultz Date: Thu, 30 May 2024 23:57:28 +1000 Subject: [PATCH 1/3] Fix fetch_scores() error if userstats dont exist --- profiles/services.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/profiles/services.py b/profiles/services.py index 521cc92..d99cdaf 100644 --- a/profiles/services.py +++ b/profiles/services.py @@ -259,9 +259,12 @@ def fetch_scores(user_id, beatmap_ids, gamemode): Fetch and add scores for a user on beatmaps in a gamemode """ # Fetch UserStats from database - user_stats = UserStats.objects.select_for_update().get( - user_id=user_id, gamemode=gamemode - ) + try: + user_stats = UserStats.objects.select_for_update().get( + user_id=user_id, gamemode=gamemode + ) + except UserStats.DoesNotExist: + return [] full_score_data_list = [] for beatmap_id in beatmap_ids: From 802efa3da16cfb4480d8e692643bebce298bce06 Mon Sep 17 00:00:00 2001 From: Samuel Cattini-Schultz Date: Fri, 31 May 2024 00:10:13 +1000 Subject: [PATCH 2/3] Fix profile updates failing if using old name --- profiles/services.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/profiles/services.py b/profiles/services.py index d99cdaf..9e6bd62 100644 --- a/profiles/services.py +++ b/profiles/services.py @@ -104,6 +104,10 @@ def refresh_user_from_api( # Doesnt exist return None + # try to fetch user stats by id in case of namechange + if user_id is None and user_stats is None: + user_stats = fetch_user(user_id=user_data["user_id"], gamemode=gamemode) + if user_stats is not None: osu_user = user_stats.user else: From 80b9cef4ce41e5facaebf226517046d96a29a97f Mon Sep 17 00:00:00 2001 From: Samuel Cattini-Schultz Date: Fri, 31 May 2024 00:20:31 +1000 Subject: [PATCH 3/3] Fix profile loading when username clashes exist --- profiles/services.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/profiles/services.py b/profiles/services.py index 9e6bd62..6f7c7d9 100644 --- a/profiles/services.py +++ b/profiles/services.py @@ -41,8 +41,11 @@ def fetch_user(user_id=None, username=None, gamemode=Gamemode.STANDARD): user_id=user_id, gamemode=gamemode ) else: - return UserStats.objects.select_related("user").get( - user__username__iexact=username, gamemode=gamemode + # usernames should really be unique, but we don't have an up to date view of the users so there may be clashes + return ( + UserStats.objects.select_related("user") + .filter(user__username__iexact=username, gamemode=gamemode) + .first() ) except UserStats.DoesNotExist: return None