Skip to content

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

Fix variants dataloader with default channel (#7206)

Tomasz Szymański02991fb9937b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d65b344024..cf98919d70 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -59,6 +59,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix incorrect payment data for klarna - #7150 by @IKarbowiak
- Drop deleted images from storage - #7129 by @IKarbowiak
- Fix core sorting on related fields - #7195 by @tomaszszymanski129
+- Fix variants dataloaders when querying with default channel - #7206 by @tomaszszymanski129
- Performance upgrade on orders query with `subtotal` field - #7174 by @tomaszszymanski129
- Performance upgrade on orders query with `actions` field - #7175 by @tomaszszymanski129
- Performance upgrade on orders query with `totalAuthorized` field - #7170 by @tomaszszymanski129
diff --git a/saleor/graphql/product/dataloaders/products.py b/saleor/graphql/product/dataloaders/products.py
index 89dd8e00fb..c68a18abee 100644
--- a/saleor/graphql/product/dataloaders/products.py
+++ b/saleor/graphql/product/dataloaders/products.py
@@ -199,7 +199,9 @@ class ProductVariantsByProductIdAndChannel(DataLoader):
def get_variants_filter(self, products_ids, channel_slugs):
return {
"product_id__in": products_ids,
- "channel_listings__channel__slug__in": channel_slugs,
+ "channel_listings__channel__slug__in": [
+ str(slug) for slug in channel_slugs
+ ],
}
@@ -211,7 +213,9 @@ class AvailableProductVariantsByProductIdAndChannel(
def get_variants_filter(self, products_ids, channel_slugs):
return {
"product_id__in": products_ids,
- "channel_listings__channel__slug__in": channel_slugs,
+ "channel_listings__channel__slug__in": [
+ str(slug) for slug in channel_slugs
+ ],
"channel_listings__price_amount__isnull": False,
}
diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.py
index 213a806a51..c08f3e0768 100644
--- a/saleor/graphql/product/tests/test_product.py
+++ b/saleor/graphql/product/tests/test_product.py
@@ -342,6 +342,42 @@ def test_product_query_by_id_available_as_app(
assert product_data["name"] == product.name
+def test_product_query_by_id_as_user(
+ user_api_client, permission_manage_products, product
+):
+ query = """
+ query ($id: ID){
+ product(id: $id) {
+ id
+ variants {
+ id
+ }
+ }
+ }
+ """
+ variables = {
+ "id": graphene.Node.to_global_id("Product", product.pk),
+ }
+
+ response = user_api_client.post_graphql(
+ query,
+ variables=variables,
+ permissions=(permission_manage_products,),
+ check_no_permissions=False,
+ )
+ content = get_graphql_content(response)
+ product_data = content["data"]["product"]
+ assert product_data is not None
+ expected_variants = [
+ {
+ "id": graphene.Node.to_global_id(
+ "ProductVariant", product.variants.first().pk
+ )
+ }
+ ]
+ assert product_data["variants"] == expected_variants
+
+
def test_product_query_by_id_not_available_as_app(
app_api_client, permission_manage_products, product, channel_USD
):