Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix core sorting on related fields (#7195)
Tomasz Szymańskidf5c8a51f969
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d63ee51eb8..ed8dfa0b60 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -58,6 +58,7 @@ All notable, unreleased changes to this project will be documented in this file.- Allow passing metadata to `accountRegister` mutation - #7152 by @piotrgrundas- 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### Breaking- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysockidiff --git a/saleor/graphql/core/connection.py b/saleor/graphql/core/connection.pyindex 8dbf3a6e0f..23e1d844f4 100644--- a/saleor/graphql/core/connection.py+++ b/saleor/graphql/core/connection.py@@ -32,7 +32,7 @@ def get_field_value(instance: DjangoModel, field_name: str):field_path = field_name.split("__")attr = instancefor elem in field_path:- attr = getattr(attr, elem)+ attr = getattr(attr, elem, None)if callable(attr):return "%s" % attr()diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex 24ab603116..8f3c55e7f5 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -5097,14 +5097,14 @@ QUERY_ORDER_WITH_SORT = """@pytest.mark.parametrize("order_sort, result_order",[- ({"field": "NUMBER", "direction": "ASC"}, [0, 1, 2]),- ({"field": "NUMBER", "direction": "DESC"}, [2, 1, 0]),- ({"field": "CREATION_DATE", "direction": "ASC"}, [1, 0, 2]),- ({"field": "CREATION_DATE", "direction": "DESC"}, [2, 0, 1]),- ({"field": "CUSTOMER", "direction": "ASC"}, [2, 0, 1]),- ({"field": "CUSTOMER", "direction": "DESC"}, [1, 0, 2]),- ({"field": "FULFILLMENT_STATUS", "direction": "ASC"}, [2, 1, 0]),- ({"field": "FULFILLMENT_STATUS", "direction": "DESC"}, [0, 1, 2]),+ ({"field": "NUMBER", "direction": "ASC"}, [0, 1, 2, 3]),+ ({"field": "NUMBER", "direction": "DESC"}, [3, 2, 1, 0]),+ ({"field": "CREATION_DATE", "direction": "ASC"}, [1, 0, 2, 3]),+ ({"field": "CREATION_DATE", "direction": "DESC"}, [3, 2, 0, 1]),+ ({"field": "CUSTOMER", "direction": "ASC"}, [2, 0, 1, 3]),+ ({"field": "CUSTOMER", "direction": "DESC"}, [3, 1, 0, 2]),+ ({"field": "FULFILLMENT_STATUS", "direction": "ASC"}, [2, 1, 0, 3]),+ ({"field": "FULFILLMENT_STATUS", "direction": "DESC"}, [3, 0, 1, 2]),],)def test_query_orders_with_sort(@@ -5151,6 +5151,15 @@ def test_query_orders_with_sort(channel=channel_USD,))+ created_orders.append(+ Order.objects.create(+ token=str(uuid.uuid4()),+ billing_address=None,+ status=OrderStatus.UNCONFIRMED,+ total=TaxedMoney(net=Money(60, "USD"), gross=Money(80, "USD")),+ channel=channel_USD,+ )+ )variables = {"sort_by": order_sort}staff_api_client.user.user_permissions.add(permission_manage_orders)response = staff_api_client.post_graphql(QUERY_ORDER_WITH_SORT, variables)