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

TypeError: object NoneType can't be used in 'await' expression #18

Open
avukalov opened this issue Jun 15, 2024 · 2 comments
Open

TypeError: object NoneType can't be used in 'await' expression #18

avukalov opened this issue Jun 15, 2024 · 2 comments

Comments

@avukalov
Copy link

Trying to run example with async repeat_at function.

from fastapi import FastAPI
from contextlib import asynccontextmanager
from fastapi_utilities import repeat_every, repeat_at


@asynccontextmanager
async def lifespan(app: FastAPI):
    # --- startup ---
    await test()
    await test2()  # ------------- await added here
    yield
    # --- shutdown ---


app = FastAPI(lifespan=lifespan)


# Repeat Every Example
@repeat_every(seconds=2)
async def test():
    print("test")


# Repeat At Example
@repeat_at(cron="* * * * *")
async def test2():  # ------------- async added here
    print("test2")

After executing command fastapi dev main.py I got this error:

INFO:     Waiting for application startup.
ERROR:    Traceback (most recent call last):
  File "C:\workspace\Learning\FastAPI\.venv\Lib\site-packages\starlette\routing.py", line 732, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1264.0_x64__qbz5n2kfra8p0\Lib\contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\workspace\Learning\FastAPI\main.py", line 11, in lifespan
    await test2()  # ------------- await added here
    ^^^^^^^^^^^^^
TypeError: object NoneType can't be used in 'await' expression

test
ERROR:    Application startup failed. Exiting.

versions:
fastapi 0.111.0
fastapi-utilities 0.2.0

@Scoowy
Copy link

Scoowy commented Oct 24, 2024

Same problem.

@priyanshu-panwar
Copy link
Owner

Hi @Scoowy
I am looking into the issue.
Can you please repeat_every till then.

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