Skip to content

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

Remvoe valueNames from AttributeInput (#18016)

Maciej Korycinski8eb11da07f09
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d617bf89a7..421666e0a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,8 +8,6 @@ All notable, unreleased changes to this project will be documented in this file.
- Increased query cost for attribute-related operations due to the addition of `AttributeValue.referencedObject`.
### 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 `pages` query.
- Use `where` to define complex conditions with `AND`/`OR` logic and operators like `eq`, `oneOf`, `range`.
- Use `search` to perform full-text search across relevant fields.
diff --git a/saleor/graphql/attribute/types.py b/saleor/graphql/attribute/types.py
index fbca7ac809..ab325dac19 100644
--- a/saleor/graphql/attribute/types.py
+++ b/saleor/graphql/attribute/types.py
@@ -544,16 +544,6 @@ class AttributeInput(BaseInputObjectType):
"with deprecated fields of `AttributeInput`. "
),
)
- value_names = NonNullList(
- graphene.String,
- required=False,
- description=(
- "Names corresponding to the attributeValues associated with the Attribute. "
- "When specified, it filters the results to include only records with "
- "one of the matching values."
- )
- + ADDED_IN_322,
- )
values = NonNullList(
graphene.String,
required=False,
diff --git a/saleor/graphql/product/filters/product_attributes.py b/saleor/graphql/product/filters/product_attributes.py
index a5ba334114..0b0259233c 100644
--- a/saleor/graphql/product/filters/product_attributes.py
+++ b/saleor/graphql/product/filters/product_attributes.py
@@ -37,7 +37,7 @@ T_PRODUCT_FILTER_QUERIES = dict[int, list[int]]
def _clean_product_attributes_filter_input(
- filter_values, field, queries, database_connection_name
+ filter_values, queries, database_connection_name
):
attribute_slugs = []
values = []
@@ -55,29 +55,29 @@ def _clean_product_attributes_filter_input(
attributes_slug_pk_map[attr_slug] = attr_pk
attributes_pk_slug_map[attr_pk] = attr_slug
- values_map = _populate_value_map(
- database_connection_name, field, values, attributes, attributes_pk_slug_map
+ values_map = _populate_slug_value_map(
+ database_connection_name, values, attributes, attributes_pk_slug_map
)
_update_queries(queries, filter_values, attributes_slug_pk_map, values_map)
-def _populate_value_map(
- database_connection_name, field, values, attribute_qs, attributes_pk_slug_map
+def _populate_slug_value_map(
+ database_connection_name, slugs, attribute_qs, attributes_pk_slug_map
):
value_maps: dict[str, dict[str, list[int]]] = defaultdict(lambda: defaultdict(list))
for (
attr_pk,
value_pk,
- field_value,
+ value_slug,
) in (
AttributeValue.objects.using(database_connection_name)
.filter(Exists(attribute_qs.filter(pk=OuterRef("attribute_id"))))
- .filter(**{f"{field}__in": values})
- .values_list("attribute_id", "pk", field)
+ .filter(slug__in=slugs)
+ .values_list("attribute_id", "pk", "slug")
):
attr_slug = attributes_pk_slug_map[attr_pk]
- value_maps[attr_slug][field_value].append(value_pk)
+ value_maps[attr_slug][value_slug].append(value_pk)
return value_maps
@@ -252,7 +252,6 @@ def filter_products_by_attributes_values_qs(qs, values_qs):
def _filter_products_by_deprecated_attributes_input(
qs,
filter_slug_values,
- filter_name_values,
filter_range_values,
filter_boolean_values,
date_range_list,
@@ -261,13 +260,7 @@ def _filter_products_by_deprecated_attributes_input(
queries: dict[int, list[int]] = defaultdict(list)
try:
if filter_slug_values:
- _clean_product_attributes_filter_input(
- filter_slug_values, "slug", queries, qs.db
- )
- if filter_name_values:
- _clean_product_attributes_filter_input(
- filter_name_values, "name", queries, qs.db
- )
+ _clean_product_attributes_filter_input(filter_slug_values, queries, qs.db)
if filter_range_values:
_clean_product_attributes_range_filter_input(
filter_range_values, queries, qs.db
@@ -296,7 +289,6 @@ def deprecated_filter_attributes(qs, value):
return qs.none()
slug_value_list = []
- name_value_list = []
boolean_list = []
value_range_list = []
date_range_list = []
@@ -306,8 +298,6 @@ def deprecated_filter_attributes(qs, value):
slug = v["slug"]
if "values" in v:
slug_value_list.append((slug, v["values"]))
- elif "value_names" in v:
- name_value_list.append((slug, v["value_names"]))
elif "values_range" in v:
value_range_list.append((slug, v["values_range"]))
elif "date" in v:
@@ -320,7 +310,6 @@ def deprecated_filter_attributes(qs, value):
qs = _filter_products_by_deprecated_attributes_input(
qs,
slug_value_list,
- name_value_list,
value_range_list,
boolean_list,
date_range_list,
diff --git a/saleor/graphql/product/tests/queries/test_products_query_with_where.py b/saleor/graphql/product/tests/queries/test_products_query_with_where.py
index 82f7c68944..04e24b9b76 100644
--- a/saleor/graphql/product/tests/queries/test_products_query_with_where.py
+++ b/saleor/graphql/product/tests/queries/test_products_query_with_where.py
@@ -744,52 +744,6 @@ def test_products_filter_by_attributes_value_slug(
assert returned_ids == {product1_id, product2_id}
-def test_products_filter_by_attributes_value_name(
- api_client,
- product_list,
- channel_USD,
-):
- # given
- product_type = ProductType.objects.create(
- name="Custom Type",
- slug="custom-type",
- has_variants=True,
- is_shipping_required=True,
- kind=ProductTypeKind.NORMAL,
- )
- attribute = Attribute.objects.create(slug="new_attr", name="Attr")
- attribute.product_types.add(product_type)
- attr_value = AttributeValue.objects.create(
- attribute=attribute, name="First", slug="first"
- )
- product = product_list[0]
- product.product_type = product_type
- product.save()
- associate_attribute_values_to_instance(
- product,
- {attribute.pk: [attr_value]},
- )
-
- variables = {
- "channel": channel_USD.slug,
- "where": {
- "attributes": [{"slug": attribute.slug, "valueNames": [attr_value.name]}],
- },
- }
-
- # when
- response = api_client.post_graphql(PRODUCTS_WHERE_QUERY, variables)
- content = get_graphql_content(response)
-
- # then
- product_id = graphene.Node.to_global_id("Product", product.id)
- products = content["data"]["products"]["edges"]
-
- assert len(products) == 1
- assert products[0]["node"]["id"] == product_id
- assert products[0]["node"]["name"] == product.name
-
-
def test_products_filter_by_attributes_empty_list(
api_client,
product_list,
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 4ba61322e4..47ede43474 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -7779,13 +7779,6 @@ input AttributeInput @doc(category: "Attributes") {
"""
value: AssignedAttributeValueInput
- """
- Names corresponding to the attributeValues associated with the Attribute. When specified, it filters the results to include only records with one of the matching values.
-
- Added in Saleor 3.22.
- """
- valueNames: [String!]
-
"""
Slugs identifying the attributeValues associated with the Attribute. When specified, it filters the results to include only records with one of the matching values. Requires `slug` to be provided.
"""