From 52242e7a00f01e3d3bfad6e7628d1c98ef04d18a Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 4 Nov 2021 08:40:38 +1100 Subject: [PATCH] Catch error --- InvenTree/part/api.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index dc521b42c6..b08834445c 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -62,7 +62,11 @@ class CategoryList(generics.ListCreateAPIView): ctx = super().get_serializer_context() - ctx['starred_categories'] = [star.category for star in self.request.user.starred_categories.all()] + try: + ctx['starred_categories'] = [star.category for star in self.request.user.starred_categories.all()] + except AttributeError: + # Error is thrown if the view does not have an associated request + ctx['starred_categories'] = [] return ctx @@ -173,7 +177,11 @@ class CategoryDetail(generics.RetrieveUpdateDestroyAPIView): ctx = super().get_serializer_context() - ctx['starred_categories'] = [star.category for star in self.request.user.starred_categories.all()] + try: + ctx['starred_categories'] = [star.category for star in self.request.user.starred_categories.all()] + except AttributeError: + # Error is thrown if the view does not have an associated request + ctx['starred_categories'] = [] return ctx