Skip to content

Commit

Permalink
Merge pull request #70 from Syriiin/fix/unranked-maps
Browse files Browse the repository at this point in the history
Fix unranked maps crashing profile updates
  • Loading branch information
Syriiin authored Jun 9, 2024
2 parents 58c847a + f206fb6 commit bab5e20
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions profiles/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ def refresh_beatmaps_from_api(beatmap_ids: Iterable[int]):
beatmap_data = osu_api_v1.get_beatmap(beatmap_id)

if beatmap_data is None:
return None
continue

beatmap = Beatmap.from_data(beatmap_data)
if beatmap.status not in [
BeatmapStatus.APPROVED,
BeatmapStatus.RANKED,
BeatmapStatus.LOVED,
]:
return None
continue

with get_default_difficulty_calculator_class(
Gamemode(beatmap.gamemode)
Expand Down Expand Up @@ -404,9 +404,14 @@ def add_scores_from_data(user_stats: UserStats, score_data_list: list[dict]):

# Update foreign keys
beatmap_id = int(score_data["beatmap_id"])
score.beatmap = next(
beatmap for beatmap in beatmaps if beatmap.id == beatmap_id
)
try:
score.beatmap = next(
beatmap for beatmap in beatmaps if beatmap.id == beatmap_id
)
except StopIteration:
# Beatmap not ranked/loved or otherwise missing
continue

score.user_stats = user_stats

gamemode = Gamemode(user_stats.gamemode)
Expand Down

0 comments on commit bab5e20

Please sign in to comment.