When a class inherits from DurableObject through an intermediate base class, calling async methods via RPC stubs fails to properly await and returns a coroutine object instead of the result.
from workers import WorkerEntrypoint, Response, DurableObject
from urllib.parse import urlparse
class MyDurableObject(DurableObject):
pass
class A(MyDurableObject):
async def foo(self):
return "foo"
class B(MyDurableObject):
async def foobar(self):
a = self.env.A.getByName("a")
foo = await a.foo()
return f"{foo}bar"
class Default(WorkerEntrypoint):
async def fetch(self, request):
match urlparse(request.url).path:
case "/foo":
a = self.env.A.getByName("a")
result = await a.foo()
case "/foobar":
b = self.env.B.getByName("b")
result = await b.foobar()
case _:
result = "not supported"
return Response(result, 200)
Behavior:
- A.foo() called directly: works
- A.foo() called via RPC stub from B: returns coroutine representation
curl http://localhost:8787/foo
foo
curl http://localhost:8787/foobar
<coroutine object _FetcherWrapper._getattr_helper.<locals>.wrapper at 0xd9a8d8>bar
The await on the RPC call is not properly resolving the async method through the inheritance chain
When a class inherits from DurableObject through an intermediate base class, calling async methods via RPC stubs fails to properly await and returns a coroutine object instead of the result.
Behavior:
curl http://localhost:8787/foofoocurl http://localhost:8787/foobar<coroutine object _FetcherWrapper._getattr_helper.<locals>.wrapper at 0xd9a8d8>barThe
awaiton the RPC call is not properly resolving the async method through the inheritance chain