Skip to content

schema: TypeError: An asyncio.Future, a coroutine or an awaitable is required #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
japrogramer opened this issue Sep 26, 2017 · 6 comments

Comments

@japrogramer
Copy link

japrogramer commented Sep 26, 2017

I always thought that graphene was fully future compliant so I thought the following line would work.
It doesn't .. is their a work around for this?
result = asyncio.wait_for(schema.execute(query, variable_values=foovar, **kwargs), 1.0)

@jkimbo
Copy link
Member

jkimbo commented Feb 17, 2018

Hi @japrogramer . We're currently going through old issues that appear to have gone stale (ie. not updated in about the last 6 months) to try and clean up the issue tracker. If this is still important to you please comment and we'll re-open this.

Thanks!

@jkimbo jkimbo closed this as completed Feb 17, 2018
@syrusakbary
Copy link
Member

Just a note, for having this working you just need to use asyncio executor:

result = asyncio.wait_for(schema.execute(query, variable_values=foovar, executor=AsyncioExecutor(), **kwargs), 1.0)

@japrogramer
Copy link
Author

@syrusakbary thanks 👍

@japrogramer
Copy link
Author

Hi im having issues now, that I have revisited this issue,
Please look at thiss
#430 (comment)

I have tried also the snipet @syrusakbary suggested above like this

            __import__('pdb').set_trace()
            result = asyncio.wait_for(schema.execute(
                          payload['query'],
                          variable_values=payload['variables'],
                          root_value=rx.Observable.create(stream).share(),
                          allow_subscriptions=True,
                          executor=AsyncioExecutor(loop=asyncio.get_event_loop()),
                          **{'context_value': message}), 1)
            result = next(result)
            __import__('pdb').set_trace()

and received this

> /app/apple/graphquery/consumers.py(75)websocket_receive()
-> result = asyncio.wait_for(schema.execute(
(Pdb) c
> /app/apple/product/schema.py(179)resolve_sub_product()
-> await make_sub(info, input.get('product'))
(Pdb) result
*** NameError: name 'result' is not defined
(Pdb) ll
177         async def resolve_sub_product(self, info, **input):
178             __import__('pdb').set_trace()
179  ->         await make_sub(info, input.get('product'))
180             name = ProductType._meta.model.__class__.__name__
181
182             stream = info.root_value
183             return stream.map(lambda message: self.next(message, info, **input))
(Pdb) n
2018-06-10 03:33:01,667 - ERROR - server - Exception inside application: An asyncio.Future, a coroutine or an awaitable is required
  File "/usr/local/lib/python3.6/site-packages/channels/sessions.py", line 175, in __call__
    return await self.inner(receive, self.send)
  File "/usr/local/lib/python3.6/site-packages/channels/consumer.py", line 54, in __call__
    await await_many_dispatch([receive, self.channel_receive], self.dispatch)
  File "/usr/local/lib/python3.6/site-packages/channels/utils.py", line 50, in await_many_dispatch
    await dispatch(result)
  File "/usr/local/lib/python3.6/site-packages/channels/consumer.py", line 67, in dispatch
    await handler(message)
  File "/app/apple/graphquery/consumers.py", line 75, in websocket_receive
    result = asyncio.wait_for(schema.execute(
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 345, in wait_for
    fut = ensure_future(fut, loop=loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 526, in ensure_future
    raise TypeError('An asyncio.Future, a coroutine or an awaitable is '
  An asyncio.Future, a coroutine or an awaitable is required
[2018/06/10 03:33:01] WebSocket DISCONNECT /gql [10.255.0.2:53120]
> /app/apple/product/schema.py(180)resolve_sub_product()
-> name = ProductType._meta.model.__class__.__name__
(Pdb)


@japrogramer
Copy link
Author

also this


  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

2018-06-10 03:38:54,786 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

[2018/06/10 03:38:54] WebSocket HANDSHAKING /gql [10.255.0.2:53170]
[2018/06/10 03:38:54] WebSocket CONNECT /gql [10.255.0.2:53170]
DJANGO DEBUG TOOLBAR ___ OK
[2018/06/10 03:38:55] HTTP GET /service-worker.js 200 [0.10, 10.255.0.2:53174]
[2018/06/10 03:38:58] WebSocket DISCONNECT /gql [10.255.0.2:53170]
DJANGO DEBUG TOOLBAR ___ OK
[2018/06/10 03:38:59] HTTP GET /admin/ 200 [0.36, 10.255.0.2:53178]
2018-06-10 03:38:59,280 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

DJANGO DEBUG TOOLBAR ___ OK
[2018/06/10 03:39:03] HTTP GET /admin/product/product/ 200 [0.27, 10.255.0.2:53184]
2018-06-10 03:39:04,070 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

DJANGO DEBUG TOOLBAR ___ OK
2018-06-10 03:39:04,084 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

[2018/06/10 03:39:04] HTTP GET /admin/jsi18n/ 200 [0.05, 10.255.0.2:53188]
2018-06-10 03:39:04,178 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

DJANGO DEBUG TOOLBAR ___ OK
[2018/06/10 03:39:06] HTTP GET /admin/product/product/1/change/ 200 [0.30, 10.255.0.2:53194]
DJANGO DEBUG TOOLBAR ___ OK
2018-06-10 03:39:06,579 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

2018-06-10 03:39:06,583 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

2018-06-10 03:39:06,585 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

[2018/06/10 03:39:06] HTTP GET /admin/jsi18n/ 200 [0.11, 10.255.0.2:53194]
2018-06-10 03:39:06,662 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.

DJANGO DEBUG TOOLBAR ___ OK
[2018/06/10 03:39:11] HTTP POST /admin/product/product/1/change/ 302 [0.20, 10.255.0.2:53206]
DJANGO DEBUG TOOLBAR ___ OK
[2018/06/10 03:39:12] HTTP GET /admin/product/product/ 200 [0.27, 10.255.0.2:53206]
DJANGO DEBUG TOOLBAR ___ OK
[2018/06/10 03:39:12] HTTP GET /admin/jsi18n/ 200 [0.05, 10.255.0.2:53206]
2018-06-10 03:39:12,235 - ERROR - http_protocol - Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/twisted/internet/defer.py", line 1386, in _inlineCallbacks
    result = g.send(result)
StopIteration: <Queue maxsize=0>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/daphne/http_protocol.py", line 166, in process
    "body": self.content.read(),
ValueError: I/O operation on closed file.




@japrogramer
Copy link
Author

@syrusakbary even tho my resolve returns an observable and is an async function whenever i pass return_promise=True,to execute i get this error
[GraphQLError('Subscription must return Async Iterable or Observable. Received: <Promise at 0x7fda4831df28 pending>',)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants