Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix failing queries with nested filters that require channel slug (#7602)
Iga Karbowiak48e3429835b2
diff --git a/saleor/graphql/core/fields.py b/saleor/graphql/core/fields.pyindex 4043f5fb6e..d4d5d898c7 100644--- a/saleor/graphql/core/fields.py+++ b/saleor/graphql/core/fields.py@@ -175,6 +175,10 @@ class FilterInputConnectionField(BaseDjangoConnectionField):cls.resolve_connection, connection, args, max_limit=max_limit)+ # for nested filters get channel from ChannelContext object+ if "channel" not in args and hasattr(root, "channel_slug"):+ args["channel"] = root.channel_slug+iterable = cls.filter_iterable(iterable, filterset_class, filters_name, info, **args)diff --git a/saleor/graphql/product/tests/test_collection.py b/saleor/graphql/product/tests/test_collection.pyindex 0ae8c86bd4..83ce8e7664 100644--- a/saleor/graphql/product/tests/test_collection.py+++ b/saleor/graphql/product/tests/test_collection.py@@ -314,7 +314,7 @@ query CollectionProducts($id: ID!,$channel: String, $filters: ProductFilterInputdef test_filter_collection_products(- user_api_client, product_list, published_collection, channel_USD+ user_api_client, product_list, published_collection, channel_USD, channel_PLN):# givenquery = GET_FILTERED_PRODUCTS_COLLECTION_QUERY@@ -340,6 +340,39 @@ def test_filter_collection_products(assert product_data["id"] == graphene.Node.to_global_id("Product", product.pk)+def test_filter_collection_published_products(+ user_api_client, product_list, published_collection, channel_USD, channel_PLN+):+ # given+ query = GET_FILTERED_PRODUCTS_COLLECTION_QUERY++ for product in product_list:+ published_collection.products.add(product)++ product = product_list[0]+ listing = product.channel_listings.first()+ listing.is_published = False+ listing.save(update_fields=["is_published"])++ product_id = graphene.Node.to_global_id("Product", product.id)++ variables = {+ "id": graphene.Node.to_global_id("Collection", published_collection.pk),+ "filters": {"isPublished": True},+ "channel": channel_USD.slug,+ }++ # when+ response = user_api_client.post_graphql(query, variables)++ # then+ content = get_graphql_content(response)+ products = content["data"]["collection"]["products"]["edges"]++ assert len(products) == len(product_list) - 1+ assert product_id not in {node["node"]["id"] for node in products}++def test_filter_collection_products_by_multiple_attributes(user_api_client,published_collection,