Skip to content

Commit

Permalink
Apply object name rules in App.lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaskom committed Feb 18, 2025
1 parent db63e01 commit 1224f0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modal/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from ._utils.function_utils import FunctionInfo, is_global_object, is_method_fn
from ._utils.grpc_utils import retry_transient_errors
from ._utils.mount_utils import validate_volumes
from ._utils.name_utils import check_object_name
from .client import _Client
from .cloud_bucket_mount import _CloudBucketMount
from .cls import _Cls, parameter
Expand Down Expand Up @@ -263,6 +264,8 @@ async def lookup(
modal.Sandbox.create("echo", "hi", app=app)
```
"""
check_object_name(name, "App")

if client is None:
client = await _Client.from_env()

Expand Down
6 changes: 6 additions & 0 deletions test/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,9 @@ def func(): # noqa: F811

app_3.include(app_4)
assert "Overriding existing function" in caplog.messages[0]


@pytest.mark.parametrize("name", ["", " ", "no way", "my-app!", "a" * 65])
def test_lookup_invalid_name(name):
with pytest.raises(InvalidError, match="Invalid App name"):
App.lookup(name)

0 comments on commit 1224f0d

Please sign in to comment.