Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Revert channel sorting param (#7756)
Tomasz Szymański684abb50d784
diff --git a/saleor/graphql/attribute/filters.py b/saleor/graphql/attribute/filters.pyindex fcf37c9616..ee563337cd 100644--- a/saleor/graphql/attribute/filters.py+++ b/saleor/graphql/attribute/filters.py@@ -8,7 +8,7 @@ from ...product import modelsfrom ..attribute.enums import AttributeTypeEnumfrom ..channel.filters import get_channel_slug_from_filter_datafrom ..core.filters import EnumFilter, MetadataFilterBase-from ..core.types import FilterInputObjectType+from ..core.types import ChannelFilterInputObjectType, FilterInputObjectTypefrom ..core.utils import from_global_id_or_errorfrom ..utils import get_user_or_app_from_contextfrom ..utils.filters import filter_fields_containing_value@@ -107,7 +107,7 @@ class AttributeFilter(MetadataFilterBase):)-class AttributeFilterInput(FilterInputObjectType):+class AttributeFilterInput(ChannelFilterInputObjectType):class Meta:filterset_class = AttributeFilterdiff --git a/saleor/graphql/attribute/tests/queries/test_attribute_filtering_with_channels.py b/saleor/graphql/attribute/tests/queries/test_attribute_filtering_with_channels.pyindex 356d9ef823..ecb35fa642 100644--- a/saleor/graphql/attribute/tests/queries/test_attribute_filtering_with_channels.py+++ b/saleor/graphql/attribute/tests/queries/test_attribute_filtering_with_channels.py@@ -192,7 +192,7 @@ def test_attributes_with_filtering_without_channel("tested_field, attribute_count",[("inCategory", 5), ("inCollection", 5)],)-def test_products_with_filtering_with_as_staff_user(+def test_products_with_filtering_with_channel_as_staff_user(tested_field,attribute_count,staff_api_client,@@ -227,6 +227,34 @@ def test_products_with_filtering_with_as_staff_user(assert len(attribute_nodes) == attribute_count+def test_products_with_alternative_filtering_with_channel_as_staff_user(+ staff_api_client,+ permission_manage_products,+ attributes_for_filtering_with_channels,+ category,+ channel_USD,+):+ # given+ filtered_by_node_id = graphene.Node.to_global_id("Category", category.pk)+ filter_by = {"inCategory": filtered_by_node_id}+ filter_by["channel"] = channel_USD.slug++ variables = {"filter": filter_by}++ # when+ response = staff_api_client.post_graphql(+ QUERY_ATTRIBUTES_FILTERING,+ variables,+ permissions=[permission_manage_products],+ check_no_permissions=False,+ )++ # then+ content = get_graphql_content(response)+ attribute_nodes = content["data"]["attributes"]["edges"]+ assert len(attribute_nodes) == 5++@pytest.mark.parametrize("tested_field, attribute_count",[("inCategory", 5), ("inCollection", 5)],diff --git a/saleor/graphql/channel/filters.py b/saleor/graphql/channel/filters.pyindex ec27fa9777..9a2b343098 100644--- a/saleor/graphql/channel/filters.py+++ b/saleor/graphql/channel/filters.py@@ -2,5 +2,5 @@ from typing import Dictdef get_channel_slug_from_filter_data(filter_data: Dict):- channel_slug = str(filter_data["channel"])- return channel_slug+ channel = filter_data.get("channel")+ return str(channel) if channel else Nonediff --git a/saleor/graphql/core/fields.py b/saleor/graphql/core/fields.pyindex d4d5d898c7..1e692d1018 100644--- a/saleor/graphql/core/fields.py+++ b/saleor/graphql/core/fields.py@@ -8,6 +8,7 @@ from graphql.error import GraphQLErrorfrom graphql_relay.connection.arrayconnection import connection_from_list_slicefrom promise import Promise+from ...channel.exceptions import ChannelNotDefined, NoDefaultChannelfrom ..channel import ChannelContext, ChannelQsContextfrom ..channel.utils import get_default_channel_slug_or_graphql_errorfrom ..utils.sorting import sort_queryset_for_connection@@ -191,8 +192,14 @@ class FilterInputConnectionField(BaseDjangoConnectionField):def filter_iterable(cls, iterable, filterset_class, filters_name, info, **args):filter_input = args.get(filters_name)if filter_input:+ try:+ filter_channel = str(filter_input["channel"])+ except (NoDefaultChannel, ChannelNotDefined, GraphQLError, KeyError):+ filter_channel = Nonefilter_input["channel"] = (- args.get("channel") or get_default_channel_slug_or_graphql_error()+ args.get("channel")+ or filter_channel+ or get_default_channel_slug_or_graphql_error())if filter_input and filterset_class:instance = filterset_class(diff --git a/saleor/graphql/core/types/__init__.py b/saleor/graphql/core/types/__init__.pyindex 2032bf6c18..fbec73b59f 100644--- a/saleor/graphql/core/types/__init__.py+++ b/saleor/graphql/core/types/__init__.py@@ -10,7 +10,7 @@ from .common import (TaxType,Weight,)-from .filter_input import FilterInputObjectType+from .filter_input import ChannelFilterInputObjectType, FilterInputObjectTypefrom .money import VAT, Money, MoneyRange, ReducedRate, TaxedMoney, TaxedMoneyRange-from .sort_input import SortInputObjectType+from .sort_input import ChannelSortInputObjectType, SortInputObjectTypefrom .upload import Uploaddiff --git a/saleor/graphql/core/types/filter_input.py b/saleor/graphql/core/types/filter_input.pyindex 1690ee0577..4cfcc03e30 100644--- a/saleor/graphql/core/types/filter_input.py+++ b/saleor/graphql/core/types/filter_input.py@@ -1,4 +1,4 @@-from graphene import InputField, InputObjectType+from graphene import Argument, InputField, InputObjectType, Stringfrom graphene.types.inputobjecttype import InputObjectTypeOptionsfrom graphene.types.utils import yank_fields_from_attrsfrom graphene_django.filter.utils import get_filterset_class@@ -62,3 +62,17 @@ class FilterInputObjectType(InputObjectType):field_type.kwargs = kwargsargs[name] = field_typereturn args+++class ChannelFilterInputObjectType(FilterInputObjectType):+ channel = Argument(+ String,+ description=(+ "Specifies the channel by which the data should be filtered."+ "DEPRECATED: Will be removed in Saleor 4.0."+ "Use root-level channel argument instead."+ ),+ )++ class Meta:+ abstract = Truediff --git a/saleor/graphql/core/types/sort_input.py b/saleor/graphql/core/types/sort_input.pyindex 31a8a35ef1..e2159a3b3f 100644--- a/saleor/graphql/core/types/sort_input.py+++ b/saleor/graphql/core/types/sort_input.py@@ -35,3 +35,17 @@ class SortInputObjectType(graphene.InputObjectType):description=f"Sort {type_name} by the selected field.",)cls._meta.fields.update({"field": field})+++class ChannelSortInputObjectType(SortInputObjectType):+ channel = graphene.Argument(+ graphene.String,+ description=(+ "Specifies the channel in which to sort the data."+ "DEPRECATED: Will be removed in Saleor 4.0."+ "Use root-level channel argument instead."+ ),+ )++ class Meta:+ abstract = Truediff --git a/saleor/graphql/discount/sorters.py b/saleor/graphql/discount/sorters.pyindex 41cbd5ab08..6fbd850b47 100644--- a/saleor/graphql/discount/sorters.py+++ b/saleor/graphql/discount/sorters.py@@ -1,7 +1,7 @@import graphenefrom django.db.models import Min, Q, QuerySet-from ..core.types import SortInputObjectType+from ..core.types import ChannelSortInputObjectTypeclass SaleSortField(graphene.Enum):@@ -28,7 +28,7 @@ class SaleSortField(graphene.Enum):)-class SaleSortingInput(SortInputObjectType):+class SaleSortingInput(ChannelSortInputObjectType):class Meta:sort_enum = SaleSortFieldtype_name = "sales"@@ -69,7 +69,7 @@ class VoucherSortField(graphene.Enum):)-class VoucherSortingInput(SortInputObjectType):+class VoucherSortingInput(ChannelSortInputObjectType):class Meta:sort_enum = VoucherSortFieldtype_name = "vouchers"diff --git a/saleor/graphql/product/filters.py b/saleor/graphql/product/filters.pyindex f8df892945..4c0ccdbc57 100644--- a/saleor/graphql/product/filters.py+++ b/saleor/graphql/product/filters.py@@ -38,7 +38,7 @@ from ..core.filters import (MetadataFilterBase,ObjectTypeFilter,)-from ..core.types import FilterInputObjectType+from ..core.types import ChannelFilterInputObjectType, FilterInputObjectTypefrom ..core.types.common import IntRangeInput, PriceRangeInputfrom ..utils import resolve_global_ids_to_primary_keysfrom ..utils.filters import filter_fields_containing_value, filter_range_field@@ -662,7 +662,7 @@ class ProductTypeFilter(MetadataFilterBase):fields = ["search", "configurable", "product_type"]-class ProductFilterInput(FilterInputObjectType):+class ProductFilterInput(ChannelFilterInputObjectType):class Meta:filterset_class = ProductFilter@@ -672,7 +672,7 @@ class ProductVariantFilterInput(FilterInputObjectType):filterset_class = ProductVariantFilter-class CollectionFilterInput(FilterInputObjectType):+class CollectionFilterInput(ChannelFilterInputObjectType):class Meta:filterset_class = CollectionFilterdiff --git a/saleor/graphql/product/sorters.py b/saleor/graphql/product/sorters.pyindex e5a5861a7c..5e98d27f6e 100644--- a/saleor/graphql/product/sorters.py+++ b/saleor/graphql/product/sorters.py@@ -22,7 +22,7 @@ from ...product.models import (Product,ProductChannelListing,)-from ..core.types import SortInputObjectType+from ..core.types import ChannelSortInputObjectType, SortInputObjectTypeclass CategorySortField(graphene.Enum):@@ -63,7 +63,7 @@ class CategorySortField(graphene.Enum):return queryset.annotate(subcategory_count=Count("children__id"))-class CategorySortingInput(SortInputObjectType):+class CategorySortingInput(ChannelSortInputObjectType):class Meta:sort_enum = CategorySortFieldtype_name = "categories"@@ -115,7 +115,7 @@ class CollectionSortField(graphene.Enum):)-class CollectionSortingInput(SortInputObjectType):+class CollectionSortingInput(ChannelSortInputObjectType):class Meta:sort_enum = CollectionSortFieldtype_name = "collections"@@ -219,7 +219,7 @@ class ProductOrderField(graphene.Enum):raise GraphQLError("Sorting by Rank is available only with searching.")-class ProductOrder(SortInputObjectType):+class ProductOrder(ChannelSortInputObjectType):attribute_id = graphene.Argument(graphene.ID,description=(diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 9fc5219e59..b43557afe6 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -513,6 +513,7 @@ input AttributeFilterInput {type: AttributeTypeEnuminCollection: IDinCategory: ID+ channel: String}input AttributeInput {@@ -808,6 +809,7 @@ enum CategorySortField {input CategorySortingInput {direction: OrderDirection!+ channel: Stringfield: CategorySortField!}@@ -1241,6 +1243,7 @@ input CollectionFilterInput {search: Stringmetadata: [MetadataFilter]ids: [ID]+ channel: String}input CollectionInput {@@ -1280,6 +1283,7 @@ enum CollectionSortField {input CollectionSortingInput {direction: OrderDirection!+ channel: Stringfield: CollectionSortField!}@@ -4305,6 +4309,7 @@ input ProductFilterInput {minimalPrice: PriceRangeInputproductTypes: [ID]ids: [ID]+ channel: String}type ProductImage {@@ -4389,6 +4394,7 @@ input ProductMediaUpdateInput {input ProductOrder {direction: OrderDirection!+ channel: StringattributeId: IDfield: ProductOrderField}@@ -4956,6 +4962,7 @@ enum SaleSortField {input SaleSortingInput {direction: OrderDirection!+ channel: Stringfield: SaleSortField!}@@ -5905,6 +5912,7 @@ enum VoucherSortField {input VoucherSortingInput {direction: OrderDirection!+ channel: Stringfield: VoucherSortField!}