Skip to content

[serve] Cannot access attribute "result" for class "DeploymentResponseGenerator" Attribute "result" is unknown #52493

@tekumara

Description

@tekumara

What happened + What you expected to happen

Image

Attribute "result" is unknown Pylance[reportAttributeAccessIssue]

If DeploymentHandle we generic in the return type of remote it could return the right type.

Versions / Dependencies

ray 2.44.1

Reproduction script

# File name: chain.py
from ray import serve
from ray.serve.handle import DeploymentHandle, DeploymentResponse


@serve.deployment
class Adder:
    def __init__(self, increment: int):
        self._increment = increment

    def __call__(self, val: int) -> int:
        return val + self._increment


@serve.deployment
class Multiplier:
    def __init__(self, multiple: int):
        self._multiple = multiple

    def __call__(self, val: int) -> int:
        return val * self._multiple


@serve.deployment
class Ingress:
    def __init__(self, adder: DeploymentHandle, multiplier: DeploymentHandle):
        self._adder = adder
        self._multiplier = multiplier

    async def __call__(self, input: int) -> int:
        adder_response: DeploymentResponse = self._adder.remote(input)
        # Pass the adder response directly into the multiplier (no `await` needed).
        multiplier_response: DeploymentResponse = self._multiplier.remote(adder_response)
        # `await` the final chained response.
        return await multiplier_response


# pyright: reportFunctionMemberAccess=false
# see https://github.com/ray-project/ray/issues/52483

app = Ingress.bind(
    Adder.bind(increment=1),
    Multiplier.bind(multiple=2),
)

handle: DeploymentHandle = serve.run(app)
response = handle.remote(5)
assert response.result() == 12, "(5 + 1) * 2 = 12" # Cannot access attribute "result" for class "DeploymentResponseGenerator"

Issue Severity

Low: It annoys or frustrates me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issue, but not time-criticalbugSomething that is supposed to be working; but isn'tcommunity-backlogpythonPull requests that update Python codeserveRay Serve Related Issueusability

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions