Skip to content

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

Unify raising permission error if user has no access to an address

Marcin Gębalabf3e9cc36d7f
diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.py
index 56e04270ef..7fb2ce3275 100644
--- a/saleor/graphql/account/mutations.py
+++ b/saleor/graphql/account/mutations.py
@@ -549,9 +549,7 @@ class CustomerSetDefaultAddress(BaseMutation):
user = info.context.user
if address not in user.addresses.all():
- cls.add_error(
- errors, 'id',
- 'The address isn\'t associated with this user.')
+ raise PermissionDenied()
if type == AddressTypeEnum.BILLING.value:
address_type = AddressType.BILLING
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 01afe7a788..d87e311eac 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -1213,6 +1213,4 @@ def test_customer_change_default_address_invalid_address(
'id': graphene.Node.to_global_id('Address', address_other_country.id),
'type': 'SHIPPING'}
response = user_api_client.post_graphql(query, variables)
- content = get_graphql_content(response)
- data = content['data']['customerSetDefaultAddress']
- assert data['errors'][0]['field'] == 'id'
+ assert_no_permission(response)