From bb540042c854615e7bb80690e764cdb40c3e70b0 Mon Sep 17 00:00:00 2001 From: Peyton Walters Date: Tue, 27 Aug 2024 19:40:06 +0000 Subject: [PATCH] Fix empty client behavior with app-attached sandboxes Previously, if a clientless app was attached to a sandbox, it would error with NoneType. This commit checks app._client to make sure it exists before using it. --- modal/sandbox.py | 2 +- test/sandbox_test.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modal/sandbox.py b/modal/sandbox.py index aed5c8df4..883e7f202 100644 --- a/modal/sandbox.py +++ b/modal/sandbox.py @@ -199,7 +199,7 @@ async def create( _experimental_gpus=_experimental_gpus, ) if client is None: - if app: + if app and app._client: client = app._client else: client = await _Client.from_env() diff --git a/test/sandbox_test.py b/test/sandbox_test.py index eae1613d1..4dbc865e7 100644 --- a/test/sandbox_test.py +++ b/test/sandbox_test.py @@ -36,6 +36,14 @@ def test_sandbox(client, servicer): assert sb.poll() == 42 +@skip_non_linux +def test_app_attached_from_env(set_env_client): + sb = Sandbox.create("echo", "hi", app=app) + sb.wait() + + assert sb.stdout.read() == "hi\n" + + @skip_non_linux def test_sandbox_mount(client, servicer, tmpdir): tmpdir.join("a.py").write(b"foo")