priyanshu-panwar / fastapi-utilities

🎨⚡️🔥 Reusable Utilities for FastAPI
https://youtu.be/ZIggeTU8JhQ?si=SO1B0Is0RdXDkbCa
MIT License
40 stars 1 forks source link

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

Open avukalov opened 5 months ago

avukalov commented 5 months ago

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 commented 3 weeks ago

Same problem.

priyanshu-panwar commented 3 weeks ago

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