Skip to content

Commit

Permalink
🥅 properly handle missing request
Browse files Browse the repository at this point in the history
  • Loading branch information
krmax44 committed Dec 13, 2024
1 parent d27b0a8 commit 21b0131
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/filingcabinet/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21b0131

Please sign in to comment.