Repository navigation
[Jobs] Fix submit_job crashing on module objects in py_modules - #66608
Conversation
There was a problem hiding this comment.
Code Review
This pull request replaces the deep copy of runtime_env with a shallow copy using dict() in submit_job to prevent failures when py_modules contains module objects that cannot be deep-copied. It also adds a unit test to verify this behavior. I have no feedback to provide.
|
Lgtm - since it's a shallow copy now, perhaps we extend the comment to say downstream code must not mutate nested values in place? |
|
Done in c7ae244. |
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
Since 2.57, JobSubmissionClient.submit_job() raises before uploading
anything when py_modules contains an imported module, one of the entry
types the runtime_env docs list:
import my_module
client.submit_job(entrypoint="...", runtime_env={"py_modules": [my_module]})
TypeError: cannot pickle 'module' object
#63990 made submit_job copy runtime_env with copy.deepcopy, so that
uploading no longer rewrites the caller's dict with gcs:// URIs (#46625).
Module objects can't be deep-copied, so the copy itself raises.
A shallow copy is enough for #46625: the working_dir and py_modules
upload helpers only rebind top-level keys and never mutate a value in
place. Path strings, URIs and `ray job submit` were never affected.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Marwan Sarieddine <[email protected]>
Review follow-up. The shallow copy still shares nested values with the caller's dict, so the steps after it must replace keys rather than mutate values in place. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Marwan Sarieddine <[email protected]>
c7ae244 to
6d28c2c
Compare
What broke
Since 2.57,
JobSubmissionClient.submit_job()raises before it uploads anything whenpy_modulescontains an imported module, which the runtime_env API reference lists as a supported entry:Expected: the module's directory is uploaded and the job runs, as on 2.56.1. A user upgrading from 2.56.1 hit this and is pinned there.
py_modulesentryTypeErrorat submitray job submit --runtime-env-jsonWhy
#63990 (the fix for #46625) made
submit_jobdeep-copyruntime_env, so that uploading stops rewriting the caller's dict withgcs://URIs. Module objects can't be deep-copied, so the copy itself raises. Nothing in CI passes a module object throughsubmit_job, so it went unnoticed.The fix
Copy shallowly:
dict(runtime_env or {}).upload_working_dir_if_neededandupload_py_modules_if_neededonly rebind top-level keys (runtime_env["py_modules"] = py_modules_uris, a new list) and never mutate a value in place, so the caller's dict and list are left alone.RuntimeEnvargument becomes a plain dict before upload and is rebuilt by the existingRuntimeEnv(**runtime_env)right after.RuntimeEnvvalidation rejects module objects, so only a plain dict can carry one.Not a duplicate
No open issue or PR covers this. The open PRs in the area don't touch the submission path: #64621 changes CLI stack traces (
cli.py,cli_utils.py), #66570 changes how nodes installpy_moduleswheels, and #65933 and #66279 change how nodes download packages. Nothing on #63990 mentions module objects.Testing
test_submit_job_with_module_object_in_py_modulesruns the real upload path behind a fake HTTP layer and checks that the module's directory is zipped with its parent (my_module/__init__.py), that the job request carries agcs://URI, and that the caller's dict still holds the module. Against the unmodifiedsdk.pyit fails withTypeError: cannot pickle 'module' object.The one failure,
test_submit_job[conda_yaml], times out because conda isn't installed on the test machine; it times out the same way with the unmodifiedsdk.py.End to end on a local cluster,
submit_job(runtime_env={"py_modules": [my_module]})now succeeds and the driver imports the module; the same script raises theTypeErrorwith the 2.58.0 wheel. Pre-commit passes on both changed files.AI assistance was used for this change.
🤖 Generated with Claude Code