Index: django-oscar-3.1/src/oscar/apps/basket/middleware.py =================================================================== --- django-oscar-3.1.orig/src/oscar/apps/basket/middleware.py +++ django-oscar-3.1/src/oscar/apps/basket/middleware.py @@ -163,8 +163,8 @@ class BasketMiddleware: basket = cookie_basket else: # Anonymous user with no basket - instantiate a new basket - # instance. No need to save yet. - basket = Basket() + # instance. + basket = Basket.objects.create(status=Basket.OPEN) # Cache basket instance for the during of this request request._basket_cache = basket Index: django-oscar-3.1/src/oscar/apps/catalogue/product_attributes.py =================================================================== --- django-oscar-3.1.orig/src/oscar/apps/catalogue/product_attributes.py +++ django-oscar-3.1/src/oscar/apps/catalogue/product_attributes.py @@ -20,7 +20,8 @@ class ProductAttributesContainer: def __init__(self, product): self.product = product - self.refresh() + if self.product.pk: + self.refresh() def refresh(self): values = self.get_values().select_related('attribute') Index: django-oscar-3.1/src/oscar/apps/catalogue/abstract_models.py =================================================================== --- django-oscar-3.1.orig/src/oscar/apps/catalogue/abstract_models.py +++ django-oscar-3.1/src/oscar/apps/catalogue/abstract_models.py @@ -598,7 +598,7 @@ class AbstractProduct(models.Model): """ Test if this product has any stockrecords """ - return self.stockrecords.exists() + return self.pk and self.stockrecords.exists() @property def num_stockrecords(self): Index: django-oscar-3.1/tests/integration/shipping/test_scales.py =================================================================== --- django-oscar-3.1.orig/tests/integration/shipping/test_scales.py +++ django-oscar-3.1/tests/integration/shipping/test_scales.py @@ -27,6 +27,7 @@ class TestScales(TestCase): def test_returns_zero_for_empty_basket(self): basket = Basket() + basket.save() scale = Scale(attribute_code='weight') self.assertEqual(0, scale.weigh_basket(basket)) Index: django-oscar-3.1/tests/integration/basket/test_models.py =================================================================== --- django-oscar-3.1.orig/tests/integration/basket/test_models.py +++ django-oscar-3.1/tests/integration/basket/test_models.py @@ -15,6 +15,7 @@ class TestANewBasket(TestCase): def setUp(self): self.basket = Basket() + self.basket.save() self.basket.strategy = strategy.Default() def test_has_zero_lines(self): Index: django-oscar-3.1/tests/integration/shipping/test_method.py =================================================================== --- django-oscar-3.1.orig/tests/integration/shipping/test_method.py +++ django-oscar-3.1/tests/integration/shipping/test_method.py @@ -12,6 +12,7 @@ class TestFreeShipppingForEmptyBasket(Te def setUp(self): self.method = methods.Free() self.basket = Basket() + self.basket.save() self.charge = self.method.calculate(self.basket) def test_is_free(self): @@ -43,6 +44,7 @@ class TestNoShippingRequired(TestCase): def setUp(self): self.method = methods.NoShippingRequired() basket = Basket() + basket.save() self.charge = self.method.calculate(basket) def test_is_free_for_empty_basket(self): @@ -59,6 +61,7 @@ class TestFixedPriceShippingWithoutTax(T def setUp(self): self.method = methods.FixedPrice(D('10.00')) basket = Basket() + basket.save() self.charge = self.method.calculate(basket) def test_has_correct_charge(self): @@ -75,6 +78,7 @@ class TestFixedPriceShippingWithTax(Test charge_excl_tax=D('10.00'), charge_incl_tax=D('12.00')) basket = Basket() + basket.save() self.charge = self.method.calculate(basket) def test_has_correct_charge(self): Index: django-oscar-3.1/src/oscar/apps/customer/apps.py =================================================================== --- django-oscar-3.1.orig/src/oscar/apps/customer/apps.py +++ django-oscar-3.1/src/oscar/apps/customer/apps.py @@ -11,6 +11,7 @@ class CustomerConfig(OscarConfig): label = 'customer' name = 'oscar.apps.customer' verbose_name = _('Customer') + default = True namespace = 'customer' Index: django-oscar-3.1/tests/integration/shipping/test_discount.py =================================================================== --- django-oscar-3.1.orig/tests/integration/shipping/test_discount.py +++ django-oscar-3.1/tests/integration/shipping/test_discount.py @@ -25,16 +25,19 @@ class TestDiscountingMethodsWithoutTax(T def test_delegates_is_tax_known(self): basket = Basket() + basket.save() charge = self.method.calculate(basket) self.assertFalse(charge.is_tax_known) def test_discounts_charge(self): basket = Basket() + basket.save() charge = self.method.calculate(basket) self.assertEqual(D('8.00'), charge.excl_tax) def test_can_have_tax_set_later(self): basket = Basket() + basket.save() charge = self.method.calculate(basket) charge.tax = D('1.00') self.assertEqual(D('9.00'), charge.incl_tax) @@ -58,10 +61,12 @@ class TestDiscountingMethodsWithTax(Test def test_delegates_is_tax_known(self): basket = Basket() + basket.save() charge = self.method.calculate(basket) self.assertTrue(charge.is_tax_known) def test_discounts_charge(self): basket = Basket() + basket.save() charge = self.method.calculate(basket) self.assertEqual(D('7.00'), charge.incl_tax)