Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Raise on first error in loops

Marcin Gębala71725d31c441
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index edbd08eb9d..756252615e 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -62,10 +62,7 @@ def clean_shipping_method(
def check_lines_quantity(variants, quantities):
- """Check if stock is sufficient for each line in the list of dicts.
- Return list of errors.
- """
- errors = {}
+ """Check if stock is sufficient for each line in the list of dicts."""
for variant, quantity in zip(variants, quantities):
try:
variant.check_quantity(quantity)
@@ -75,10 +72,7 @@ def check_lines_quantity(variants, quantities):
+ '%(item_name)s. Only %(remaining)d remaining in stock.' % {
'remaining': e.item.quantity_available,
'item_name': e.item.display_product()})
- ValidationError({'quantity': message}).update_error_dict(errors)
-
- if errors:
- raise ValidationError(errors)
+ raise ValidationError({'quantity': message})
class CheckoutLineInput(graphene.InputObjectType):
@@ -331,12 +325,6 @@ class CheckoutCustomerDetach(BaseMutation):
errors = []
checkout = cls.get_node_or_error(
info, checkout_id, errors, 'checkout_id', only_type=Checkout)
-
- # FIXME: is this error actually useful? IN this case mutation could just do nothing
- if not checkout.user:
- raise ValidationError(
- 'There\'s no customer assigned to this Checkout.')
-
checkout.user = None
checkout.save(update_fields=['user'])
return CheckoutCustomerDetach(checkout=checkout)
diff --git a/saleor/graphql/menu/mutations.py b/saleor/graphql/menu/mutations.py
index 989c5bec86..8f74a413fc 100644
--- a/saleor/graphql/menu/mutations.py
+++ b/saleor/graphql/menu/mutations.py
@@ -67,8 +67,7 @@ class MenuCreate(ModelMutation):
page = item.get('page')
url = item.get('url')
if len([i for i in [category, collection, page, url] if i]) > 1:
- ValidationError({
- 'items': 'More than one item provided.'}).update_error_dict(errors)
+ raise ValidationError({'items': 'More than one item provided.'})
else:
if category:
category = cls.get_node_or_error(
@@ -84,8 +83,7 @@ class MenuCreate(ModelMutation):
info, page, errors, 'items', only_type=Page)
item['page'] = page
elif not url:
- ValidationError({
- 'items': 'No menu item provided.'}).update_error_dict(errors)
+ raise ValidationError({'items': 'No menu item provided.'})
items.append(item)
if errors:
@@ -207,7 +205,7 @@ class AssignNavigation(BaseMutation):
menu = graphene.Field(Menu, description='Assigned navigation menu.')
class Arguments:
- menu = graphene.ID(description='ID of the menu.') # FIXME: required=True?
+ menu = graphene.ID(description='ID of the menu.')
navigation_type = NavigationType(
description='Type of the navigation bar to assign the menu to.',
required=True)
diff --git a/tests/api/test_checkout.py b/tests/api/test_checkout.py
index d7aa61816f..984785b909 100644
--- a/tests/api/test_checkout.py
+++ b/tests/api/test_checkout.py
@@ -612,21 +612,6 @@ def test_checkout_customer_detach(
assert cart.user is None
-def test_checkout_customer_detach_without_customer(
- user_api_client, cart_with_item):
- cart = cart_with_item
-
- checkout_id = graphene.Node.to_global_id('Checkout', cart.pk)
- variables = {
- 'checkoutId': checkout_id, }
- response = user_api_client.post_graphql(
- MUTATION_CHECKOUT_CUSTOMER_DETACH, variables)
- content = get_graphql_content(response)
- data = content['data']['checkoutCustomerDetach']
- assert data['errors'][0][
- 'message'] == 'There\'s no customer assigned to this Checkout.'
-
-
MUTATION_CHECKOUT_SHIPPING_ADDRESS_UPDATE = """
mutation checkoutShippingAddressUpdate(
$checkoutId: ID!, $shippingAddress: AddressInput!) {