Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Disable logs about bad requests for GraphQL API (#17798)
Marcin Gębala15c83896fd60
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d30455be23..b9d315b0ca 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,7 @@ All notable, unreleased changes to this project will be documented in this file.### Breaking changes### GraphQL API+- Added support for filtering products by attribute value names. The `AttributeInput` now includes a `valueNames` field, enabling filtering by the names of attribute values, in addition to the existing filtering by value slugs.- You can now filter and search orders using the new `where` and `search` fields on the `orders` query.- Use `where` to define complex conditions with `AND`/`OR` logic and operators like `eq`, `oneOf`, `range`.@@ -25,8 +26,29 @@ All notable, unreleased changes to this project will be documented in this file.### Other changes- Add JSON schemas for synchronous webhooks, now available in `saleor/json_schemas.py`. These schemas define the expected structure of webhook responses sent back to Saleor, enabling improved validation and tooling support for integrations. This change helps ensure that responses from webhook consumers meet Saleor’s expectations and can be reliably processed.+- deps: upgraded urllib3 from v1.x to v2.x- Fix PAGE_DELETE webhook to include pageType in payload - #17697 by @Jennyyyy0212 and @CherineCho2016- Stripe Plugin has been deprecated. It will be removed in the future. Please use [the Stripe App](https://docs.saleor.io/developer/app-store/apps/stripe/overview) instead- App Extensions: Added new allowed extension target: NEW_TAB. Once handled in the Dashboard, an extension will be able to open a link in new tab- App Extensions: New mount points for Dashboard categories, collections, gift cards, draft orders, discounts, vouchers, pages, pages types and menus+- Changed logging settings of failed requests to reduce logs amount in production:++ - Downgraded the "A query had an error" log from INFO to DEBUG level.+ - Increased the `django.request` logger's level to ERROR, to reduce the number of WARNING logs for failed GraphQL or 404 requests.++ Previously, a failed GraphQL request (up to Saleor 3.21) would generate the following logs:++ ```+ 2025-06-06 13:26:06,104 INFO saleor.graphql.errors.handled A query had an error [PID:21676:ThreadPoolExecutor-5_0]+ 2025-06-06 13:26:06,107 WARNING django.request Bad Request: /graphql/ [PID:21676:ThreadPoolExecutor-6_0]+ INFO: 127.0.0.1:63244 - "POST /graphql/ HTTP/1.1" 400 Bad Request+ ```++ Starting from Saleor 3.22, the same request logs only the HTTP-level message:++ ```+ INFO: 127.0.0.1:63345 - "POST /graphql/ HTTP/1.1" 400 Bad Request+ ```++ 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.diff --git a/saleor/graphql/core/tests/test_view.py b/saleor/graphql/core/tests/test_view.pyindex 43eede2e4f..5201ba6219 100644--- a/saleor/graphql/core/tests/test_view.py+++ b/saleor/graphql/core/tests/test_view.py@@ -1,4 +1,5 @@import json+import loggingfrom unittest import mockfrom unittest.mock import patch@@ -155,26 +156,45 @@ def test_graphql_execution_exception(monkeypatch, api_client):def test_invalid_query_graphql_errors_are_logged_in_another_logger(api_client, graphql_log_handler):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)++ # whenresponse = api_client.post_graphql("{ shop }")++ # thenassert response.status_code == 400assert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]def test_invalid_syntax_graphql_errors_are_logged_in_another_logger(api_client, graphql_log_handler):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)++ # whenresponse = api_client.post_graphql("{ }")++ # thenassert response.status_code == 400assert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLSyntaxError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLSyntaxError"]def test_permission_denied_query_graphql_errors_are_logged_in_another_logger(api_client, graphql_log_handler):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)++ # whenresponse = api_client.post_graphql("""mutation {@@ -186,9 +206,11 @@ def test_permission_denied_query_graphql_errors_are_logged_in_another_logger(}""")++ # thenassert response.status_code == 200assert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].PermissionDenied"+ "saleor.graphql.errors.handled[DEBUG].PermissionDenied"]@@ -253,6 +275,9 @@ def test_unexpected_exceptions_are_logged_in_their_own_logger(def test_query_contains_not_only_schema_raise_error(other_query, api_client, graphql_log_handler):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)query = """query IntrospectionQuery {%(other_query)s@@ -263,10 +288,14 @@ def test_query_contains_not_only_schema_raise_error(}}"""++ # whenresponse = api_client.post_graphql(query % {"other_query": other_query})++ # thenassert response.status_code == 400assert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]diff --git a/saleor/graphql/menu/tests/queries/test_menu.py b/saleor/graphql/menu/tests/queries/test_menu.pyindex de6132de7d..006153771f 100644--- a/saleor/graphql/menu/tests/queries/test_menu.py+++ b/saleor/graphql/menu/tests/queries/test_menu.py@@ -1,3 +1,5 @@+import logging+import graphenefrom .....menu.models import Menu@@ -101,6 +103,9 @@ def test_menu_query_error_when_id_and_name_provided(graphql_log_handler,):# given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)+variables = {"id": graphene.Node.to_global_id("Menu", menu.pk),"name": menu.name,@@ -111,7 +116,7 @@ def test_menu_query_error_when_id_and_name_provided(# thenassert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]content = get_graphql_content(response, ignore_errors=True)assert len(content["errors"]) == 1@@ -123,6 +128,8 @@ def test_menu_query_error_when_no_param(graphql_log_handler,):# given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)variables = {}# when@@ -130,7 +137,7 @@ def test_menu_query_error_when_no_param(# thenassert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]content = get_graphql_content(response, ignore_errors=True)assert len(content["errors"]) == 1diff --git a/saleor/graphql/product/tests/queries/test_product_query.py b/saleor/graphql/product/tests/queries/test_product_query.pyindex d824a5699a..32acb5446c 100644--- a/saleor/graphql/product/tests/queries/test_product_query.py+++ b/saleor/graphql/product/tests/queries/test_product_query.py@@ -1,4 +1,5 @@import datetime+import loggingfrom unittest.mock import MagicMockimport graphene@@ -1383,13 +1384,20 @@ def test_product_query_error_when_id_and_slug_provided(product,graphql_log_handler,):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)variables = {"id": graphene.Node.to_global_id("Product", product.pk),"slug": product.slug,}++ # whenresponse = user_api_client.post_graphql(QUERY_PRODUCT, variables=variables)++ # thenassert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]content = get_graphql_content(response, ignore_errors=True)assert len(content["errors"]) == 1@@ -1400,10 +1408,17 @@ def test_product_query_error_when_no_param(product,graphql_log_handler,):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)variables = {}++ # whenresponse = user_api_client.post_graphql(QUERY_PRODUCT, variables=variables)++ # thenassert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]content = get_graphql_content(response, ignore_errors=True)assert len(content["errors"]) == 1diff --git a/saleor/graphql/product/tests/test_category.py b/saleor/graphql/product/tests/test_category.pyindex 8dac7b8435..9b2e9766ef 100644--- a/saleor/graphql/product/tests/test_category.py+++ b/saleor/graphql/product/tests/test_category.py@@ -1,4 +1,5 @@import json+import loggingimport osfrom unittest.mock import MagicMock, Mock, patch@@ -251,15 +252,22 @@ def test_category_query_by_translated_slug(def test_category_query_error_when_id_and_slug_provided(user_api_client, product, graphql_log_handler, channel_USD):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)category = Category.objects.first()variables = {"id": graphene.Node.to_global_id("Category", category.pk),"slug": category.slug,"channel": channel_USD.slug,}++ # whenresponse = user_api_client.post_graphql(QUERY_CATEGORY, variables=variables)++ # thenassert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]content = get_graphql_content(response, ignore_errors=True)assert len(content["errors"]) == 1@@ -268,10 +276,17 @@ def test_category_query_error_when_id_and_slug_provided(def test_category_query_error_when_no_param(user_api_client, product, graphql_log_handler):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)variables = {}++ # whenresponse = user_api_client.post_graphql(QUERY_CATEGORY, variables=variables)++ # thenassert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]content = get_graphql_content(response, ignore_errors=True)assert len(content["errors"]) == 1diff --git a/saleor/graphql/product/tests/test_collection.py b/saleor/graphql/product/tests/test_collection.pyindex 489560bda9..b79534d6d6 100644--- a/saleor/graphql/product/tests/test_collection.py+++ b/saleor/graphql/product/tests/test_collection.py@@ -1,4 +1,5 @@import datetime+import loggingimport osfrom unittest.mock import MagicMock, Mock, patch@@ -138,13 +139,20 @@ def test_collection_query_error_when_id_and_slug_provided(collection,graphql_log_handler,):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)variables = {"id": graphene.Node.to_global_id("Collection", collection.pk),"slug": collection.slug,}++ # whenresponse = user_api_client.post_graphql(QUERY_COLLECTION, variables=variables)++ # thenassert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]content = get_graphql_content(response, ignore_errors=True)assert len(content["errors"]) == 1@@ -155,10 +163,17 @@ def test_collection_query_error_when_no_param(collection,graphql_log_handler,):+ # given+ handled_errors_logger = logging.getLogger("saleor.graphql.errors.handled")+ handled_errors_logger.setLevel(logging.DEBUG)variables = {}++ # whenresponse = user_api_client.post_graphql(QUERY_COLLECTION, variables=variables)++ # thenassert graphql_log_handler.messages == [- "saleor.graphql.errors.handled[INFO].GraphQLError"+ "saleor.graphql.errors.handled[DEBUG].GraphQLError"]content = get_graphql_content(response, ignore_errors=True)assert len(content["errors"]) == 1diff --git a/saleor/graphql/utils/__init__.py b/saleor/graphql/utils/__init__.pyindex a0086ed0f7..f0d8932c70 100644--- a/saleor/graphql/utils/__init__.py+++ b/saleor/graphql/utils/__init__.py@@ -290,7 +290,7 @@ def format_error(error, handled_exceptions, query=None):if query:exc._exc_query = queryif isinstance(exc, handled_exceptions):- handled_errors_logger.info("A query had an error", exc_info=exc)+ handled_errors_logger.debug("A query had an error", exc_info=exc)else:unhandled_errors_logger.error("A query failed unexpectedly", exc_info=exc)diff --git a/saleor/settings.py b/saleor/settings.pyindex c003da1f19..2681e8d31e 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -415,6 +415,11 @@ LOGGING = {},},"loggers": {+ "django.request": {+ "handlers": ["default"],+ "level": "ERROR",+ "propagate": False,+ },"django": {"level": "INFO", "propagate": True},"django.server": {"handlers": ["django.server"],