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][Fix] Fix "No error is raised when the "bind" args does not match the function signature" #47773

Merged
merged 7 commits into from
Dec 6, 2024

Conversation

rkooo567
Copy link
Contributor

@rkooo567 rkooo567 commented Sep 21, 2024

Why are these changes needed?

bind doesn't check if the arg matches the signature. Fortunately, we already have the logic in .remote that checks it, and we just use the same mechanism. This also provides very nice error message;

Screenshot 2024-09-21 at 12 09 09 AM

Related issue number

Closes #47598
Closes #47709

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@rkooo567 rkooo567 changed the title [Core][] [Core][Fix] Fix "No error is raised when the "bind" args does not match the function signature" Sep 21, 2024
Copy link
Contributor

@ruisearch42 ruisearch42 left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.

python/ray/dag/tests/experimental/test_accelerated_dag.py Outdated Show resolved Hide resolved
python/ray/actor.py Outdated Show resolved Hide resolved
python/ray/actor.py Show resolved Hide resolved
Comment on lines 271 to 283
try:
signature.flatten_args(self._signature, args, kwargs)
except TypeError as e:
signature_copy = self._signature.copy()
if len(signature_copy) > 0 and signature_copy[-1].name == "_ray_trace_ctx":
# Remove the trace context arg for readability.
signature_copy.pop(-1)
signature_copy = inspect.Signature(parameters=signature_copy)
raise TypeError(
f"{str(e)}. The function `{self._method_name}` has a signature "
f"`{signature_copy}`, but it doesn't match a given argument to a "
f"bind function. args: {args}. kwargs: {kwargs}."
) from None
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be wrapped into another util method like flatten_args in signature.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created a new API validate_args.

For this question, I feel like adding error message here is better (since it needs to access several private attribute. Feel awkward to create a separate util func)

python/ray/actor.py Outdated Show resolved Hide resolved
@rkooo567
Copy link
Contributor Author

rkooo567 commented Dec 2, 2024

cc @ruisearch42 can you take a look again?

@rkooo567 rkooo567 added the go add ONLY when ready to merge, run all tests label Dec 2, 2024
@ruisearch42
Copy link
Contributor

Just noticed this message, I will review soon!

python/ray/dag/tests/experimental/test_accelerated_dag.py Outdated Show resolved Hide resolved
python/ray/actor.py Outdated Show resolved Hide resolved
python/ray/actor.py Show resolved Hide resolved
python/ray/_private/signature.py Outdated Show resolved Hide resolved
@ruisearch42
Copy link
Contributor

Need to fix DCO

@rkooo567 rkooo567 merged commit 062df98 into ray-project:master Dec 6, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
3 participants