Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing queries with nested filters that require channel slug #7602

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions saleor/graphql/core/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ def connection_resolver(
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
)
Expand Down
35 changes: 34 additions & 1 deletion saleor/graphql/product/tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_collections_query_as_staff_without_channel(


def test_filter_collection_products(
user_api_client, product_list, published_collection, channel_USD
user_api_client, product_list, published_collection, channel_USD, channel_PLN
):
# given
query = GET_FILTERED_PRODUCTS_COLLECTION_QUERY
Expand All @@ -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,
Expand Down