This commit is contained in:
Josh Warwick 2023-05-05 16:28:40 +01:00
parent c501fdb20b
commit 58b92e6ed3
4 changed files with 10 additions and 5 deletions

View File

@ -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(

View File

@ -159,12 +159,14 @@ class SerializerMutation(ClientIDMutation):
except RuntimeError:
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():

View File

@ -290,6 +290,7 @@ class DjangoObjectType(ObjectType):
try:
try:
import asyncio
asyncio.get_running_loop()
except RuntimeError:
pass

View File

@ -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