From 803529c40e2e722a5037d0de4ddd66e92ce51047 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Thu, 28 Mar 2024 10:50:52 +0100 Subject: [PATCH] FIX AttributeError if no anonymous basket in session. --- oscarapi/views/basic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/oscarapi/views/basic.py b/oscarapi/views/basic.py index 16face17..cc6b6626 100644 --- a/oscarapi/views/basic.py +++ b/oscarapi/views/basic.py @@ -71,6 +71,7 @@ class BasketList(generics.ListAPIView): def get_queryset(self): qs = super(BasketList, self).get_queryset() + mapped_with_baskets = [] if self.request.user.is_authenticated: qs = qs.filter(owner=self.request.user) mapped_with_baskets = list( @@ -78,7 +79,8 @@ def get_queryset(self): ) else: # anonymous users have max 1 basket. basket = get_anonymous_basket(self.request) - mapped_with_baskets = [prepare_basket(basket, self.request)] + if basket is not None: + mapped_with_baskets = [prepare_basket(basket, self.request)] return QuerySetList(mapped_with_baskets, qs)