Skip to content

Commit

Permalink
Quickfix for leaking implementation objects when using Modal objects …
Browse files Browse the repository at this point in the history
…as cls parameters (#2534)
  • Loading branch information
freider authored Nov 19, 2024
1 parent a3f594a commit ed5ccfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions modal/cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ async def lookup(
await resolver.load(obj)
return obj

@synchronizer.no_input_translation
def __call__(self, *args, **kwargs) -> _Obj:
"""This acts as the class constructor."""
return _Obj(
Expand Down
17 changes: 17 additions & 0 deletions test/cls_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,3 +1007,20 @@ class D:
@app.function(serialized=True)
def f(self):
pass


def test_modal_object_param_uses_wrapped_type(servicer, set_env_client, client):
with servicer.intercept() as ctx:
with modal.Dict.ephemeral() as dct:
with baz_app.run():
# create bound instance:
typing.cast(modal.Cls, Baz(x=dct)).keep_warm(1)

req: api_pb2.FunctionBindParamsRequest = ctx.pop_request("FunctionBindParams")
function_def: api_pb2.Function = servicer.app_functions[req.function_id]
from modal._container_entrypoint import deserialize_params

_client = typing.cast(modal.client._Client, synchronizer._translate_in(client))
container_params = deserialize_params(req.serialized_params, function_def, _client)
args, kwargs = container_params
assert type(kwargs["x"]) == type(dct)

0 comments on commit ed5ccfb

Please sign in to comment.