Skip to content
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

Error thrown : TypeError: object list can't be used in 'await' expression #36

Closed
omshankar1 opened this issue Sep 19, 2021 · 4 comments
Closed

Comments

@omshankar1
Copy link

File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 398, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in call
return await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 208, in call
await super().call(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 112, in call
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in call
raise exc from None
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in call
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.8/site-packages/timing_asgi/middleware.py", line 68, in call
await self.app(scope, receive, send_wrapper)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/cors.py", line 86, in call
await self.simple_response(scope, receive, send, request_headers=headers)
File "/usr/local/lib/python3.8/site-packages/starlette/middleware/cors.py", line 142, in simple_response
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in call
raise exc from None
File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in call
await self.app(scope, receive, sender)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 580, in call
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
response = await func(request)
File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 226, in app
raw_response = await run_endpoint_function(
File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 159, in run_endpoint_function
return await dependant.call(**values)
File "/usr/local/lib/python3.8/site-packages/fastapi_cache/decorator.py", line 47, in inner
ret = await func(*args, **kwargs)
TypeError: object list can't be used in 'await' expression

@long2ice
Copy link
Owner

the function should be async

@PieroValdebenito
Copy link

Example

Wrong ❌

@app.get("/")
cache(expire=30)
def healcheck():
    return {'status': 'OK'}

Good ✅

@app.get("/")
cache(expire=30)
async def healcheck():
    return {'status': 'OK'}

@a5r0n
Copy link

a5r0n commented Nov 24, 2021

According to the official documentation of fastapi,
functions can (and should) be synchronous if necessary. (E.g. for interacting with DB)
https://fastapi.tiangolo.com/async/#in-a-hurry

the workaround is simple check asyncio.iscoroutinefunction(func)..

@long2ice
Copy link
Owner

Because we use aioredis, aiobotocore inside etc.

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

4 participants