# Ray serve: no attribute 'add\_done\_callback'

**URL:** <https://discuss.ray.io/t/ray-serve-no-attribute-add-done-callback/10697>\
**Category:** Ray Serve\
**Created:** [May 17, 2023, 12:03pm UTC](https://discuss.ray.io/t/ray-serve-no-attribute-add-done-callback/10697 "2023-05-17T12:03:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cedricdeboom](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/cedricdeboom/32/4447_2.png) [@cedricdeboom](https://discuss.ray.io/u/cedricdeboom)\
**Post date:** [May 17, 2023, 12:03pm UTC](https://discuss.ray.io/t/ray-serve-no-attribute-add-done-callback/10697/1 "2023-05-17T12:03:00Z")

</div>

I try the basic HTTP ingress example of Ray Serve ([Key Concepts — Ray 2.8.0](https://docs.ray.io/en/latest/serve/key-concepts.html#ingress-deployment-http-handling)), but whenever I launch a post request, I get a `AttributeError: ‘ray._raylet.ObjectRef’ object has no attribute ‘add_done_callback’` error (complete stack trace below). This happens in the FastAPI ingress example.

In the raw starlette Request example, I get the error:

> TypeError: ‘coroutine’ object is not subscriptable

On this line:

> name = await request.json()[“name”]

I use a poetry project in which I have installed the following:

> [tool.poetry.dependencies]  
> python = “^3.11”  
> flask = “^2.3.2”  
> pyopenssl = “^23.1.1”  
> gunicorn = “^20.1.0”  
> ray = {extras = [“serve”], version = “^2.4.0”}  
> requests = “^2.30.0”  
> fastapi = “^0.95.2”

The Ray server is launched using the command

> poetry run serve run --port 4444 --host 0.0.0.0 src.project.model.serve:basic\_ingress

Complete stack trace:

> (HTTPProxyActor pid=1781699) ERROR: Exception in ASGI application  
> (HTTPProxyActor pid=1781699) Traceback (most recent call last):  
> (HTTPProxyActor pid=1781699) File “/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/h11\_impl.py”, line 428, in run\_asgi  
> (HTTPProxyActor pid=1781699) result = await app( # type: ignore[func-returns-value]  
> (HTTPProxyActor pid=1781699) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> (HTTPProxyActor pid=1781699) File “/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy\_headers.py”, line 78, in **call**  
> (HTTPProxyActor pid=1781699) return await self.app(scope, receive, send)  
> (HTTPProxyActor pid=1781699) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> (HTTPProxyActor pid=1781699) File “/.venv/lib/python3.11/site-packages/ray/serve/\_private/http\_proxy.py”, line 404, in **call**  
> (HTTPProxyActor pid=1781699) status\_code = await \_send\_request\_to\_handle(handle, scope, receive, send)  
> (HTTPProxyActor pid=1781699) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> (HTTPProxyActor pid=1781699) File “/.venv/lib/python3.11/site-packages/ray/serve/\_private/http\_proxy.py”, line 117, in \_send\_request\_to\_handle  
> (HTTPProxyActor pid=1781699) \_, request\_timed\_out = await asyncio.wait(  
> (HTTPProxyActor pid=1781699) ^^^^^^^^^^^^^^^^^^^  
> (HTTPProxyActor pid=1781699) File “/.conda/envs/python3.11/lib/python3.11/asyncio/tasks.py”, line 418, in wait  
> (HTTPProxyActor pid=1781699) return await \_wait(fs, timeout, return\_when, loop)  
> (HTTPProxyActor pid=1781699) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
> (HTTPProxyActor pid=1781699) File “/.conda/envs/python3.11/lib/python3.11/asyncio/tasks.py”, line 522, in \_wait  
> (HTTPProxyActor pid=1781699) f.add\_done\_callback(\_on\_completion)  
> (HTTPProxyActor pid=1781699) ^^^^^^^^^^^^^^^^^^^  
> (HTTPProxyActor pid=1781699) AttributeError: ‘ray.\_raylet.ObjectRef’ object has no attribute ‘add\_done\_callback’

---

<div class="post-metadata">

**Author:** ![cedricdeboom](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/cedricdeboom/32/4447_2.png) [@cedricdeboom](https://discuss.ray.io/u/cedricdeboom)\
**Post date:** [May 19, 2023, 11:05am UTC](https://discuss.ray.io/t/ray-serve-no-attribute-add-done-callback/10697/2 "2023-05-19T11:05:56Z")

</div>

FYI: I solved it by using Python 3.10 instead of Python 3.11…

---

<div class="post-metadata">

**Author:** ![joso](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/joso/32/3745_2.png) [@joso](https://discuss.ray.io/u/joso)\
**Post date:** [June 9, 2023, 1:21pm UTC](https://discuss.ray.io/t/ray-serve-no-attribute-add-done-callback/10697/3 "2023-06-09T13:21:03Z")

</div>

Thank you for posting a solution to your problem as well.  
Is there maybe a potential solution which supports use of Python 3.11 as well? 🙂

---

<div class="post-metadata">

**Author:** ![Oblynx](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/oblynx/32/6471_2.png) [@Oblynx](https://discuss.ray.io/u/Oblynx)\
**Post date:** [November 18, 2024, 6:37pm UTC](https://discuss.ray.io/t/ray-serve-no-attribute-add-done-callback/10697/4 "2024-11-18T18:37:34Z")

</div>

I see a very similar issue after upgrading to python 3.11.

- ray: 2.38.0
- fastapi: 0.94.1

```auto
AttributeError: 'DeploymentResponse' object has no attribute 'add_done_callback'

```

I’m looking more into FastAPI – maybe it’s solved in later versions?

---

<div class="post-metadata">

**Author:** ![cindy\_zhang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/cindy_zhang/32/3559_2.png) [@cindy\_zhang](https://discuss.ray.io/u/cindy_zhang)\
**Post date:** [November 18, 2024, 11:41pm UTC](https://discuss.ray.io/t/ray-serve-no-attribute-add-done-callback/10697/5 "2024-11-18T23:41:49Z")

</div>

Hi @Oblynx could you post more info on what code you ran, and where you saw this error?

---

<div class="post-metadata">

**Author:** ![Oblynx](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/oblynx/32/6471_2.png) [@Oblynx](https://discuss.ray.io/u/Oblynx)\
**Post date:** [November 27, 2024, 3:00pm UTC](https://discuss.ray.io/t/ray-serve-no-attribute-add-done-callback/10697/6 "2024-11-27T15:00:11Z")

</div>

Hey, coming back to this with some extra info.

The object is `ray.serve.handle.DeploymentResponse`. It ends up raising:

```auto
> f.add_done_callback(_on_completion)
E AttributeError: 'DeploymentResponse' object has no attribute 'add_done_callback'

/usr/lib/python3.11/asyncio/tasks.py:532: AttributeError

```

Why are we trying to use it this way?  
The user code does:

- `await asyncio.wait([coro], timeout=timeout)`
- where `coro: ray.serve.handle.DeploymentResponse = model_handle.preprocess.remote(...)`
- where `model_handle: ray.serve.handle.DeploymentHandle`

---

<div class="post-metadata">

**Author:** ![Oblynx](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/oblynx/32/6471_2.png) [@Oblynx](https://discuss.ray.io/u/Oblynx)\
**Post date:** [November 27, 2024, 5:56pm UTC](https://discuss.ray.io/t/ray-serve-no-attribute-add-done-callback/10697/7 "2024-11-27T17:56:11Z")

</div>

Essentially what happens in Python 3.11 is that `asyncio.wait` calls the method `add_done_callback` that is defined in the stdlib [Task](https://docs.python.org/3.11/library/asyncio-task.html#asyncio.Task.add_done_callback) and [Future](https://docs.python.org/3.11/library/asyncio-future.html#asyncio.Future.add_done_callback) interface.

I currently use this workaround:

```auto
if isinstance(coro, DeploymentResponse):
    coro = asyncio.ensure_future(coro)
await asyncio.wait([coro], timeout=timeout)

```
