Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shamspias opened this issue Oct 25, 2022 · 3 comments · May be fixed by #339
Open

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

shamspias opened this issue Oct 25, 2022 · 3 comments · May be fixed by #339
Labels

Comments

@shamspias
Copy link

shamspias commented Oct 25, 2022

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
Copy link
Member

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

@shamspias
Copy link
Author

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants