django-oscar / django-oscar-api

RESTful JSON API for django-oscar
Other
369 stars 160 forks source link

AttributeError: 'NoneType' object has no attribute 'strategy' #300

Open shamspias opened 1 year ago

shamspias commented 1 year ago

when trying to fetch baskets API to get anonymous cart information it shows

AttributeError: 'NoneType' object has no attribute 'strategy'

API: /api/baskets/ request: GET view: BasketList

problem point: oscarapi/views/basic.py 78 number line.

        else:  # anonymous users have max 1 basket.
            basket = get_anonymous_basket(self.request)
            mapped_with_baskets = [prepare_basket(basket, self.request)]

if no cart/basket is in session it shows an error but needs an error handler.

specialunderwear commented 1 year ago

That is not the correct api to fetch a users basket. You should use /api/basket/

shamspias commented 1 year ago

That is not the correct API to fetch a user's basket. You should use /api/basket/

Thanks to let me know. but why this API: /api/baskets/ then ? at least if it's useless then it should be removed right? at let's need remove the lines

oscarapi/views/basic.py

        else:  # anonymous users have max 1 basket.
            basket = get_anonymous_basket(self.request)
            mapped_with_baskets = [prepare_basket(basket, self.request)]
JulienPalard commented 6 months ago

In our context we have sessions disabled, so we can't have an anonymous basket in the session, which leads to this AttributeError too.

A way to fix it could be, in class BasketList(generics.ListAPIView): to check the result of get_anonymous_basket against Null and just return an empty list if it's the case.

While I'm at it, I'm opening #339.