From b8b7dcc1d166aa463f5b8624d1521b0e329656f6 Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Tue, 18 Nov 2025 12:34:55 +0300 Subject: [PATCH 1/2] Features: Fixes: 1) Replace `Count("id")` with `Count("pk")` in commerce queries; 2) Fix `User.objects.get(...)` call by using `uuid` directly instead of accessing nested `serializer.validated_data["user"]["uuid"]`; 3) Add missing closing parenthesis in `VerifyJSONWebToken` call. Extra: Minor code cleanup and consistency in UUID access pattern across mutations. --- engine/core/utils/commerce.py | 4 ++-- engine/vibes_auth/graphene/mutations.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/engine/core/utils/commerce.py b/engine/core/utils/commerce.py index 47fe83e9..7afa27b5 100644 --- a/engine/core/utils/commerce.py +++ b/engine/core/utils/commerce.py @@ -81,7 +81,7 @@ def get_daily_finished_orders_count(period: timedelta = timedelta(days=30)) -> d Order.objects.filter(status="FINISHED", buy_time__lte=current, buy_time__gte=period_start) .annotate(day=TruncDate("buy_time")) .values("day") - .annotate(cnt=Count("id")) + .annotate(cnt=Count("pk")) .order_by("day") ) result: dict[date, int] = {} @@ -169,7 +169,7 @@ def get_customer_mix(period: timedelta = timedelta(days=30)) -> dict[str, int]: return {"new": 0, "returning": 0} lifetime_counts = ( - Order.objects.filter(status="FINISHED", user_id__in=period_users).values("user_id").annotate(c=Count("id")) + Order.objects.filter(status="FINISHED", user_id__in=period_users).values("user_id").annotate(c=Count("pk")) ) new_cnt = 0 ret_cnt = 0 diff --git a/engine/vibes_auth/graphene/mutations.py b/engine/vibes_auth/graphene/mutations.py index 4ec6a070..5e39966b 100644 --- a/engine/vibes_auth/graphene/mutations.py +++ b/engine/vibes_auth/graphene/mutations.py @@ -205,7 +205,7 @@ class ObtainJSONWebToken(BaseMutation): try: serializer.is_valid(raise_exception=True) return ObtainJSONWebToken( - user=User.objects.get(serializer.validated_data["user"]["uuid"]), + user=User.objects.get(uuid=serializer.validated_data["user"]["uuid"]), refresh_token=serializer.validated_data["refresh"], access_token=serializer.validated_data["access"], ) @@ -226,7 +226,7 @@ class RefreshJSONWebToken(BaseMutation): try: serializer.is_valid(raise_exception=True) return RefreshJSONWebToken( - user=User.objects.get(serializer.validated_data["user"]["uuid"]), + user=User.objects.get(uuid=serializer.validated_data["user"]["uuid"]), access_token=serializer.validated_data["access"], refresh_token=serializer.validated_data["refresh"], ) @@ -248,7 +248,7 @@ class VerifyJSONWebToken(BaseMutation): serializer.is_valid(raise_exception=True) # noinspection PyTypeChecker return VerifyJSONWebToken( - token_is_valid=True, user=User.objects.get(serializer.validated_data["user"]["uuid"]) + token_is_valid=True, user=User.objects.get(uuid=serializer.validated_data["user"]["uuid"]) ) detail = traceback.format_exc() if settings.DEBUG else "" # noinspection PyTypeChecker From 770d3a935d236e2697d5180b2a28ad3247aeea6c Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Tue, 18 Nov 2025 12:51:51 +0300 Subject: [PATCH 2/2] Features: None Fixes: 1) Update model type references from `payments.models.Transaction` to `engine.payments.models.Transaction`; 2) Update model type references from `core.models.Order` to `engine.core.models.Order`; Extra: Consistent namespace fix across multiple files; no functional changes. --- engine/core/graphene/mutations.py | 12 ++++++------ engine/core/viewsets.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/core/graphene/mutations.py b/engine/core/graphene/mutations.py index 81bb917d..3078aaa0 100644 --- a/engine/core/graphene/mutations.py +++ b/engine/core/graphene/mutations.py @@ -228,9 +228,9 @@ class BuyOrder(BaseMutation): ) match str(type(instance)): - case "": + case "": return BuyOrder(transaction=instance) - case "": + case "": return BuyOrder(order=instance) case _: raise TypeError(_(f"wrong type came from order.buy() method: {type(instance)!s}")) @@ -493,9 +493,9 @@ class BuyWishlist(BaseMutation): instance = order.buy(force_balance=force_balance, force_payment=force_payment) match str(type(instance)): - case "": + case "": return BuyWishlist(transaction=instance) - case "": + case "": return BuyWishlist(order=instance) case _: raise TypeError(_(f"wrong type came from order.buy() method: {type(instance)!s}")) @@ -535,9 +535,9 @@ class BuyProduct(BaseMutation): order.add_product(product_uuid=product_uuid, attributes=format_attributes(attributes)) instance = order.buy(force_balance=force_balance, force_payment=force_payment) match str(type(instance)): - case "": + case "": return BuyProduct(transaction=instance) - case "": + case "": return BuyProduct(order=instance) case _: raise TypeError(_(f"wrong type came from order.buy() method: {type(instance)!s}")) diff --git a/engine/core/viewsets.py b/engine/core/viewsets.py index bce34d89..11e25493 100644 --- a/engine/core/viewsets.py +++ b/engine/core/viewsets.py @@ -704,9 +704,9 @@ class OrderViewSet(EvibesViewSet): chosen_products=serializer.validated_data.get("chosen_products"), ) match str(type(instance)): - case "": + case "": return Response(status=status.HTTP_202_ACCEPTED, data=TransactionProcessSerializer(instance).data) - case "": + case "": return Response(status=status.HTTP_200_OK, data=OrderDetailSerializer(instance).data) case _: raise TypeError(_(f"wrong type came from order.buy() method: {type(instance)!s}"))