From 19de6f1be198062df8d195b7cb87b8f15230d23a Mon Sep 17 00:00:00 2001 From: Daniel Ursache Dogariu Date: Sat, 25 May 2024 14:51:56 +0300 Subject: [PATCH] NGO slug validator handling of Anonymous User --- backend/donations/views/api.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/donations/views/api.py b/backend/donations/views/api.py index 648d7193..2959266d 100644 --- a/backend/donations/views/api.py +++ b/backend/donations/views/api.py @@ -68,8 +68,13 @@ def validate_ngo_slug(cls, user, slug): return HttpResponseBadRequest() ngo_queryset = Ngo.objects - if user.ngo: - ngo_queryset = ngo_queryset.exclude(id=user.ngo.id) + + try: + if user.ngo: + ngo_queryset = ngo_queryset.exclude(id=user.ngo.id) + except AttributeError: + # Anonymous users don't have the .ngo attribute + pass if ngo_queryset.filter(slug=slug.lower()).count(): return HttpResponseBadRequest()