Skip to content

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

fix(graphql): missing error handling when no channel in DB (#19068)

Mikail9bf2755c9bd0
diff --git a/saleor/graphql/account/tests/mutations/account/test_request_email_change.py b/saleor/graphql/account/tests/mutations/account/test_request_email_change.py
index f28963648d..e2307584f5 100644
--- a/saleor/graphql/account/tests/mutations/account/test_request_email_change.py
+++ b/saleor/graphql/account/tests/mutations/account/test_request_email_change.py
@@ -242,3 +242,23 @@ def test_request_email_change_send_event(
account_change_email_requested_mock.assert_called_once_with(
customer_user, channel_PLN.slug, "token", change_email_url, new_email
)
+
+
+def test_request_email_change_but_no_channels_exist(user_api_client, customer_user):
+ """It should return an error when no channel exist in DB."""
+ variables = {
+ "password": "password",
+ "new_email": "[email protected]",
+ "redirect_url": "http://www.example.com",
+ }
+ response = user_api_client.post_graphql(REQUEST_EMAIL_CHANGE_QUERY, variables)
+ content = get_graphql_content(response)
+ data = content["data"]["requestEmailChange"]
+ assert not data["user"]
+ assert data["errors"] == [
+ {
+ "code": "MISSING_CHANNEL_SLUG",
+ "message": "You need to provide channel slug.",
+ "field": "channel",
+ }
+ ]
diff --git a/saleor/graphql/channel/utils.py b/saleor/graphql/channel/utils.py
index 43cbe0bf46..ac3ffd4719 100644
--- a/saleor/graphql/channel/utils.py
+++ b/saleor/graphql/channel/utils.py
@@ -70,7 +70,7 @@ def clean_channel(
else:
try:
channel = get_default_channel(allow_replica)
- except ChannelNotDefined as e:
+ except (ChannelNotDefined, NoDefaultChannel) as e:
raise ValidationError(
{
"channel": ValidationError(