RecursionError FastApi и SQLAlchemy

При переходе по ссылке определенной, мы удаляем запись, но почему-то вызывается рекурсия.

@app.get('/delete_rev_{pk}')
   def delete_review(pk: int = Path(...)):
   r = delete_review(pk)
   return RedirectResponse('/panel', status_code=302)

def delete_review(id):
   r = session.query(Reviews).get(id)
   session.delete(r)
   session.commit()
   return None

Сама ошибка:

Traceback (most recent call last):
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 407, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/fastapi/applications.py", line 270, in __call__
    await super().__call__(scope, receive, send)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/starlette/routing.py", line 706, in __call__
    await route.handle(scope, receive, send)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/fastapi/routing.py", line 237, in app
    raw_response = await run_endpoint_function(
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/fastapi/routing.py", line 165, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/starlette/concurrency.py", line 41, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/anyio/to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "/home/avgust/Документы/py_shit/pet_choc/venv/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "/home/avgust/Документы/py_shit/pet_choc/main.py", line 82, in delete_review
    r = delete_review(pk)
  File "/home/avgust/Документы/py_shit/pet_choc/main.py", line 82, in delete_review
    r = delete_review(pk)
  File "/home/avgust/Документы/py_shit/pet_choc/main.py", line 82, in delete_review
    r = delete_review(pk)
  [Previous line repeated 992 more times]
RecursionError: maximum recursion depth exceeded

Ответы (0 шт):