django-oscar / django-oscar-api

RESTful JSON API for django-oscar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

shamspias opened this issue · comments

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.

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

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)]

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.