From 21b0131b0b0f181704d278fec5dde56b53ab064d Mon Sep 17 00:00:00 2001 From: krmax44 Date: Fri, 13 Dec 2024 11:14:24 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20properly=20handle=20missing=20re?= =?UTF-8?q?quest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/filingcabinet/api_views.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/filingcabinet/api_views.py b/src/filingcabinet/api_views.py index e2816c1..0414884 100644 --- a/src/filingcabinet/api_views.py +++ b/src/filingcabinet/api_views.py @@ -186,13 +186,14 @@ def get_serializer_context(self): return ctx # FIXME: check if directory is part of this collection + parent_directory = None try: - dir_id = int(self.request.GET.get("directory", "")) - parent_directory = CollectionDirectory.objects.get(id=dir_id) - except (ValueError, CollectionDirectory.DoesNotExist, AttributeError): # request is not available when called from manage.py generateschema - # request.GET therefore raises an AttributeError - parent_directory = None + if self.request is not None: + dir_id = int(self.request.GET.get("directory", "")) + parent_directory = CollectionDirectory.objects.get(id=dir_id) + except (ValueError, CollectionDirectory.DoesNotExist): + pass ctx.update({"parent_directory": parent_directory}) return ctx