Skip to content

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

Make email filter case insensitive for user query (#17874)

Smit Parmarb97d1d9c7064
diff --git a/CHANGELOG.md b/CHANGELOG.md
index adad68f242..5c78cfc847 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -117,3 +117,5 @@ All notable, unreleased changes to this project will be documented in this file.
To see details of why a GraphQL request is failing, you can use OpenTelemetry tracing, where each span for a failing request will be marked with an error flag and will include an error message.
- Fixed bug when not-authenticated staff user couldn't fetch `appExtension.app` without `MANAGE_APPS`. Now apps access is available by staff users and the app itself (for app and extension it owns)
+
+- Fixed bug in user email filtering to make it case-insensitive.
diff --git a/saleor/graphql/account/resolvers.py b/saleor/graphql/account/resolvers.py
index cc14bbf63f..67e56aeb2b 100644
--- a/saleor/graphql/account/resolvers.py
+++ b/saleor/graphql/account/resolvers.py
@@ -67,7 +67,7 @@ def resolve_user(info, id=None, email=None, external_reference=None):
if id:
_model, filter_kwargs["pk"] = from_global_id_or_error(id, User)
if email:
- filter_kwargs["email"] = email
+ filter_kwargs["email__iexact"] = email.lower()
if external_reference:
filter_kwargs["external_reference"] = external_reference
if requester.has_perms(
diff --git a/saleor/graphql/account/tests/queries/test_user.py b/saleor/graphql/account/tests/queries/test_user.py
index a55379f183..8f9db02274 100644
--- a/saleor/graphql/account/tests/queries/test_user.py
+++ b/saleor/graphql/account/tests/queries/test_user.py
@@ -604,6 +604,19 @@ def test_query_user_by_email_address(
assert customer_user.email == data["email"]
+def test_query_user_by_email_address_case_insensitive(
+ user_api_client, customer_user, permission_manage_users
+):
+ email = customer_user.email
+ variables = {"email": email.upper()}
+ response = user_api_client.post_graphql(
+ USER_QUERY, variables, permissions=[permission_manage_users]
+ )
+ content = get_graphql_content(response)
+ data = content["data"]["user"]
+ assert customer_user.email == data["email"]
+
+
def test_query_user_by_external_reference(
user_api_client, customer_user, permission_manage_users
):