From cf28db9fd0800e97b7c909b67826b93038f8a855 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 7 Nov 2025 08:49:30 +0100 Subject: [PATCH] avoid getting mails for get_object_or_404 failures --- tournaments/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tournaments/views.py b/tournaments/views.py index c3d2f38..d9dfb2c 100644 --- a/tournaments/views.py +++ b/tournaments/views.py @@ -69,6 +69,12 @@ from .models import AnimationType logger = logging.getLogger(__name__) +def get_object(type, id): + try: + return type.objects.get(pk=id) + except (type.DoesNotExist, ValueError, ValidationError): + raise Http404(f"{type.__name__} does not exist") + def index(request): now = timezone.now() thirty_days_ago = now - timedelta(days=30) @@ -118,7 +124,7 @@ def tournaments_query(query, club_id, ascending, limit=None): club = None if club_id: - club = get_object_or_404(Club, pk=club_id) + club = get_object(Club, club_id) q_club = Q(event__club=club) queries.append(q_club) else: