premier fix pour le discord bot qui envoie des reminders sur des versions de matchs qui n'existent plus
CI - Security, Lint & Tests / validate (push) Failing after 1m5s
CI - Security, Lint & Tests / validate (push) Failing after 1m5s
This commit is contained in:
+25
-3
@@ -583,6 +583,12 @@ def edit_match(match_id):
|
||||
notified_player_ids = []
|
||||
notified_participant_ids = []
|
||||
|
||||
# Capture old participant ids before any deletion, so we can purge
|
||||
# their pending Discord notifications once the change is committed.
|
||||
stale_participant_ids = [
|
||||
p.id for p in MatchParticipant.query.filter_by(match_id=match.id).all()
|
||||
]
|
||||
|
||||
if match.match_type == 'team_vs_team':
|
||||
teams_changed = data['team1_id'] != match.team1_id or data['team2_id'] != match.team2_id
|
||||
if teams_changed:
|
||||
@@ -593,17 +599,33 @@ def edit_match(match_id):
|
||||
else:
|
||||
# Same teams: the roster stands, but everyone is told again,
|
||||
# because the date or the time may have moved.
|
||||
# Reuse the existing participant ids so reference_id is always
|
||||
# a real participant row, never the match id (fallback).
|
||||
for team_id in (match.team1_id, match.team2_id):
|
||||
if team_id:
|
||||
notified_player_ids.extend(
|
||||
m.player_id for m in TeamMember.query.filter_by(team_id=team_id).all()
|
||||
)
|
||||
for member in TeamMember.query.filter_by(team_id=team_id).all():
|
||||
notified_player_ids.append(member.player_id)
|
||||
existing = MatchParticipant.query.filter_by(
|
||||
match_id=match.id, player_id=member.player_id
|
||||
).first()
|
||||
if existing:
|
||||
notified_participant_ids.append(existing.id)
|
||||
stale_participant_ids = [
|
||||
pid for pid in stale_participant_ids if pid != existing.id
|
||||
]
|
||||
else:
|
||||
MatchParticipant.query.filter_by(match_id=match.id).delete()
|
||||
notified_player_ids, notified_participant_ids = create_participants(match, data)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Purge Discord pending entries for participants that no longer exist.
|
||||
# This runs after the commit so the bot only sees the durable state.
|
||||
if stale_participant_ids:
|
||||
from app.discord_bot import purge_pending_for_participants
|
||||
|
||||
purge_pending_for_participants(stale_participant_ids)
|
||||
|
||||
notify_participants(
|
||||
title=match.title,
|
||||
date=match.date,
|
||||
|
||||
Reference in New Issue
Block a user