mirror of
https://github.com/vale981/ray
synced 2025-03-05 10:01:43 -05:00
[Core] Force get_actor(name)'s name to be non-empty string (#12218)
This commit is contained in:
parent
32d159a2ed
commit
7f1f16d99e
3 changed files with 11 additions and 0 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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__]))
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue