From 58b92e6ed3e505b57a46162d42b23b2ea2d56353 Mon Sep 17 00:00:00 2001 From: Josh Warwick Date: Fri, 5 May 2023 16:28:40 +0100 Subject: [PATCH] linting --- graphene_django/filter/fields.py | 2 ++ graphene_django/rest_framework/mutation.py | 6 ++++-- graphene_django/types.py | 5 +++-- setup.py | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/graphene_django/filter/fields.py b/graphene_django/filter/fields.py index c62ee9c..a4ae821 100644 --- a/graphene_django/filter/fields.py +++ b/graphene_django/filter/fields.py @@ -95,6 +95,7 @@ class DjangoFilterConnectionField(DjangoConnectionField): qs = super().resolve_queryset(connection, iterable, info, args) if info.is_awaitable(qs): + async def filter_async(qs): filterset = filterset_class( data=filter_kwargs(), queryset=await qs, request=info.context @@ -102,6 +103,7 @@ class DjangoFilterConnectionField(DjangoConnectionField): if await sync_to_async(filterset.is_valid)(): return filterset.qs raise ValidationError(filterset.form.errors.as_json()) + return filter_async(qs) filterset = filterset_class( diff --git a/graphene_django/rest_framework/mutation.py b/graphene_django/rest_framework/mutation.py index 8cdd470..46d3593 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -154,17 +154,19 @@ class SerializerMutation(ClientIDMutation): kwargs = cls.get_serializer_kwargs(root, info, **input) serializer = cls._meta.serializer_class(**kwargs) - try: + try: get_running_loop() except RuntimeError: - pass + pass else: + async def perform_mutate_async(): if await sync_to_async(serializer.is_valid)(): return await sync_to_async(cls.perform_mutate)(serializer, info) else: errors = ErrorType.from_errors(serializer.errors) return cls(errors=errors) + return perform_mutate_async() if serializer.is_valid(): diff --git a/graphene_django/types.py b/graphene_django/types.py index 068d268..a064b90 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -288,14 +288,15 @@ class DjangoObjectType(ObjectType): def get_node(cls, info, id): queryset = cls.get_queryset(cls._meta.model.objects, info) try: - try: + try: import asyncio + asyncio.get_running_loop() except RuntimeError: pass else: return queryset.aget(pk=id) - + return queryset.get(pk=id) except cls._meta.model.DoesNotExist: return None diff --git a/setup.py b/setup.py index 64273e2..56a13b4 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ tests_require = [ "pytz", "django-filter>=22.1", "pytest-django>=4.5.2", - "pytest-asyncio>=0.16,<2" + "pytest-asyncio>=0.16,<2", ] + rest_framework_require