Skip to content

Commit

Permalink
Raise ValueError when product has no stockrecord
Browse files Browse the repository at this point in the history
When adding product to basket, Oscar expects that strategy provides
stockrecord. If there is no stockrecord, strange errors are raise, e.g.
NoneType has no attributed id.

This patch provides a more meaningful error.

Fixes #1037
  • Loading branch information
izidormatusov committed Dec 3, 2013
1 parent 1b474d7 commit 19523ae
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions oscar/apps/basket/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ def add_product(self, product, quantity=1, options=None):
"line has currency %s, while basket has currency %s") % (
stock_info.price.currency, price_currency))

if stock_info.stockrecord is None:
raise ValueError((
"Basket lines must all have stock records. Strategy hasn't "
"found any stock record for product %s") % product)

# Line reference is used to distinguish between variations of the same
# product (eg T-shirts with different personalisations)
line_ref = self._create_line_reference(
Expand Down

0 comments on commit 19523ae

Please sign in to comment.