Skip to content

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

Fix prefetching address for warehouses query

Michał Sipa9303ec098848
diff --git a/saleor/graphql/warehouse/filters.py b/saleor/graphql/warehouse/filters.py
index c2b66e44cc..d9f39ee967 100644
--- a/saleor/graphql/warehouse/filters.py
+++ b/saleor/graphql/warehouse/filters.py
@@ -7,7 +7,7 @@ from ..utils import filter_by_query_param
def prefech_qs_for_filter(qs):
- return qs.select_related("address")
+ return qs.prefetch_related("address")
def filter_search_warehouse(qs, _, value):
diff --git a/tests/api/test_warehouse.py b/tests/api/test_warehouse.py
index 5b04a88193..df933eb3f8 100644
--- a/tests/api/test_warehouse.py
+++ b/tests/api/test_warehouse.py
@@ -56,6 +56,21 @@ query Warehouses($filters: WarehouseFilterInput) {
}
"""
+QUERY_WERHOUSES_WITH_FILTERS_NO_IDS = """
+query Warehouses($filters: WarehouseFilterInput) {
+ warehouses(first:100, filter: $filters) {
+ totalCount
+ edges {
+ node {
+ name
+ companyName
+ email
+ }
+ }
+ }
+}
+"""
+
QUERY_WAREHOUSE = """
query warehouse($id: ID!){
warehouse(id: $id) {
@@ -298,6 +313,29 @@ def test_query_warehouse_with_filters_by_id(
assert content_exists["data"]["warehouses"]["totalCount"] == 1
+def test_query_warehouses_with_filters_and_no_id(
+ staff_api_client, permission_manage_products, warehouse
+):
+ variables_exists = {"filters": {"search": "test"}}
+ response_exists = staff_api_client.post_graphql(
+ QUERY_WAREHOUSES_WITH_FILTERS,
+ variables=variables_exists,
+ permissions=[permission_manage_products],
+ )
+ content_exists = get_graphql_content(response_exists)
+ warehouse_id = graphene.Node.to_global_id("Warehouse", warehouse.id)
+ content_warehouse = content_exists["data"]["warehouses"]["edges"][0]["node"]
+ assert content_warehouse["id"] == warehouse_id
+
+ variable_does_not_exists = {"filters": {"search": "[email protected]"}}
+ response_not_exists = staff_api_client.post_graphql(
+ QUERY_WAREHOUSES_WITH_FILTERS, variables=variable_does_not_exists
+ )
+ content_not_exists = get_graphql_content(response_not_exists)
+ total_count = content_not_exists["data"]["warehouses"]["totalCount"]
+ assert total_count == 0
+
+
def test_mutation_create_warehouse(
staff_api_client, permission_manage_products, shipping_zone
):