Skip to content

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

Refactor sort queryset utils

fowczarekbcdfdef53b14
diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.py
index dc1d4dc84b..4b9b5c9584 100644
--- a/saleor/graphql/utils.py
+++ b/saleor/graphql/utils.py
@@ -139,10 +139,8 @@ def sort_queryset(
direction = sort_by.direction
sorting_field = sort_by.field
- custom_sort_by_name = f"sort_by_{sorting_field}"
-
- if custom_sort_by_name in dir(sort_enum):
- custom_sort_by = getattr(sort_enum, custom_sort_by_name)
+ custom_sort_by = getattr(sort_enum, f"sort_by_{sorting_field}", None)
+ if custom_sort_by:
queryset = custom_sort_by(queryset, sort_by)
else:
queryset = queryset.order_by(f"{direction}{sorting_field}")