[Core] Force get_actor(name)'s name to be non-empty string (#12218)

This commit is contained in:
Ian Rodney 2020-11-23 12:38:16 -08:00 committed by GitHub
parent 32d159a2ed
commit 7f1f16d99e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View file

@ -216,6 +216,9 @@ public final class RayNativeRuntime extends AbstractRayRuntime {
@SuppressWarnings("unchecked")
@Override
public <T extends BaseActorHandle> Optional<T> getActor(String name, boolean global) {
if (name.isEmpty()) {
return Optional.empty();
}
byte[] actorIdBytes = nativeGetActorIdOfNamedActor(name, global);
ActorId actorId = ActorId.fromBytes(actorIdBytes);
if (actorId.isNil()) {

View file

@ -1032,6 +1032,12 @@ def test_kill(ray_start_regular_shared):
ray.kill("not_an_actor_handle")
def test_get_actor_no_input(ray_start_regular_shared):
for bad_name in [None, "", " "]:
with pytest.raises(ValueError):
ray.get_actor(bad_name)
if __name__ == "__main__":
import pytest
sys.exit(pytest.main(["-v", __file__]))

View file

@ -1538,6 +1538,8 @@ def get_actor(name):
Raises:
ValueError if the named actor does not exist.
"""
if not name:
raise ValueError("Please supply a non-empty value to get_actor")
worker = global_worker
worker.check_connected()
handle = worker.core_worker.get_named_actor_handle(name)