Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Only raise RayTaskError if user exception cannot be subclassed. #44379

Merged
merged 25 commits into from
Apr 12, 2024

Conversation

rynewang
Copy link
Contributor

When a Ray Task raises user exceptions, the exception is forwarded to the caller of ray.get(obj_ref) where caller can catch it. For ease of use, Ray makes a dual exception that inherits both RayTaskError and the user exception type, so it can be caught as either.

Problem is, if the user exception is marked @final, we can't make such a dual exception. Notably, Pydantic v2 ValidationError is @final. This PR handles such case by issuing a warning and only raise the RayTaskError. The user exception can be accessed as ray_task_error.cause.

Fixes #43401.

… the caller of `ray.get(obj_ref)` where caller can catch it. For ease of use, Ray makes a *dual* exception that inherits both `RayTaskError` and the user exception type, so it can be caught as either.

Problem is, if the user exception is marked `@final`, we can't make such a dual exception. Notably, Pydantic v2 ValidationError is `@final`. This PR handles such case by issuing a warning and only raise the `RayTaskError`. The user exception can be accessed as `ray_task_error.cause`.

Signed-off-by: Ruiyang Wang <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
@rynewang rynewang requested a review from a team as a code owner April 2, 2024 13:20
doc/source/ray-core/doc_code/task_exceptions.py Outdated Show resolved Hide resolved
python/ray/tests/test_failure.py Outdated Show resolved Hide resolved
python/ray/exceptions.py Outdated Show resolved Hide resolved
python/ray/tests/test_failure.py Outdated Show resolved Hide resolved
doc/source/ray-core/fault_tolerance/tasks.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@angelinalg angelinalg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some style nits. Please let me know if you have questions. Correct any meanings I might have mangled. In particular, I don't know who "user" is. If it's the reader, just remove phrases like "user can"

doc/source/ray-core/fault_tolerance/tasks.rst Outdated Show resolved Hide resolved
python/ray/exceptions.py Outdated Show resolved Hide resolved
python/ray/exceptions.py Outdated Show resolved Hide resolved
python/ray/exceptions.py Outdated Show resolved Hide resolved
python/ray/exceptions.py Outdated Show resolved Hide resolved
python/ray/tests/test_failure.py Outdated Show resolved Hide resolved
python/ray/tests/test_pydantic_serialization.py Outdated Show resolved Hide resolved
python/ray/tests/test_pydantic_serialization.py Outdated Show resolved Hide resolved
python/ray/tests/test_pydantic_serialization.py Outdated Show resolved Hide resolved
python/ray/tests/test_pydantic_serialization.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@jjyao jjyao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. Let's address doc comments and we can merge it.

doc/source/ray-core/doc_code/task_exceptions.py Outdated Show resolved Hide resolved
doc/source/ray-core/doc_code/task_exceptions.py Outdated Show resolved Hide resolved
rynewang and others added 12 commits April 11, 2024 23:11
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Co-authored-by: angelinalg <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
Signed-off-by: Ruiyang Wang <[email protected]>
python/ray/tests/test_pydantic_serialization.py Outdated Show resolved Hide resolved
@jjyao
Copy link
Collaborator

jjyao commented Apr 11, 2024

Test failed and is related.

@jjyao jjyao merged commit d4df414 into ray-project:master Apr 12, 2024
5 checks passed
@rynewang rynewang deleted the final-exc branch April 12, 2024 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Core] Pydantic ValidationErrors cannot be handled by Ray
5 participants