-
Notifications
You must be signed in to change notification settings - Fork 562
fix(Ray): Retain the original function name when patching Ray tasks #4858
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import inspect | ||
import functools | ||
import sys | ||
|
||
import sentry_sdk | ||
|
@@ -17,7 +18,6 @@ | |
import ray # type: ignore[import-not-found] | ||
except ImportError: | ||
raise DidNotEnable("Ray not installed.") | ||
import functools | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
|
@@ -54,6 +54,7 @@ def new_remote(f=None, *args, **kwargs): | |
|
||
def wrapper(user_f): | ||
# type: (Callable[..., Any]) -> Any | ||
@functools.wraps(user_f) | ||
def new_func(*f_args, _tracing=None, **f_kwargs): | ||
# type: (Any, Optional[dict[str, Any]], Any) -> Any | ||
_check_sentry_initialized() | ||
|
@@ -78,6 +79,19 @@ def new_func(*f_args, _tracing=None, **f_kwargs): | |
|
||
return result | ||
|
||
# Patching new_func signature to add the _tracing parameter to it | ||
# Ray later inspects the signature and finds the unexpected parameter otherwise | ||
signature = inspect.signature(new_func) | ||
params = list(signature.parameters.values()) | ||
params.append( | ||
inspect.Parameter( | ||
"_tracing", | ||
kind=inspect.Parameter.KEYWORD_ONLY, | ||
default=None, | ||
) | ||
) | ||
new_func.__signature__ = signature.replace(parameters=params) | ||
|
||
Comment on lines
+84
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential bug: Adding the
|
||
if f: | ||
rv = old_remote(new_func) | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Tracing Parameter Patching Causes Signature Errors
The
_tracing
parameter patching logic unconditionally appends the parameter, which can lead to two issues: aValueError
ifuser_f
already defines_tracing
, or an invalid signature if**kwargs
is present, as keyword-only parameters must precede**kwargs
.