Skip to content

Commit ad7c113

Browse files
authored
Merge pull request #3861 from cloudflare/dominik/fixes-rpc-python
Fixes Python RPC using Pyodide patch.
2 parents f3eb3cc + 115a1c6 commit ad7c113

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

build/python_metadata.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ BUNDLE_VERSION_INFO = make_bundle_version_info([
6767
"pyodide_version": "0.26.0a2",
6868
"pyodide_date": "2024-03-01",
6969
"packages": "20240829.4",
70-
"backport": 28,
71-
"integrity": "sha256-a2F/YpfjuGsVIsx5Z/WSbAaWSHL9vO13puPxX+wKwNI=",
70+
"backport": "29",
71+
"integrity": "sha256-sVWQzDU+mUsVOp481/oCUuDAWEbKKuc4gxToLVezg6g=",
7272
"feature_flags": [],
7373
"emscripten_version": "3.1.52",
7474
"python_version": "3.12.1",
@@ -79,8 +79,8 @@ BUNDLE_VERSION_INFO = make_bundle_version_info([
7979
"pyodide_version": "0.27.1",
8080
"pyodide_date": "2025-01-16",
8181
"packages": "20250324.1",
82-
"backport": 16,
83-
"integrity": "sha256-znvAe5OAidJcQyeWeMFClJ5LPgP0QPztxZW/sogb1wI=",
82+
"backport": "17",
83+
"integrity": "sha256-jV3zgLs1uevw2s9woVGdcRTjkqTWEOg5ToMAWS1mo8w=",
8484
"feature_flags": ["pythonWorkers20250116"],
8585
"emscripten_version": "3.1.58",
8686
"python_version": "3.12.7",

src/pyodide/helpers.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def _python_bundle(version, *, pyodide_asm_wasm = None, pyodide_asm_js = None, p
107107
console.error("Failed to read ", libName, e);
108108
}
109109
}
110+
111+
function patchedApplyFunc(func, this_, args) {
112+
return Function.prototype.apply.apply(func, [this_, args]);
113+
}
110114
"""
111115

112116
REPLACEMENTS = [
@@ -166,6 +170,11 @@ def _python_bundle(version, *, pyodide_asm_wasm = None, pyodide_asm_js = None, p
166170
"getMemory(",
167171
"Module.getMemoryPatched(Module, libName, ",
168172
],
173+
# to fix RPC, applies https://github.com/pyodide/pyodide/commit/8da1f38f7
174+
[
175+
"nullToUndefined(func.apply(",
176+
"nullToUndefined(patchedApplyFunc(func, ",
177+
],
169178
]
170179

171180
expand_template(

src/workerd/io/compatibility-date.capnp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
431431
pythonWorkers @43 :Bool
432432
$compatEnableFlag("python_workers")
433433
$pythonSnapshotRelease(pyodide = "0.26.0a2", pyodideRevision = "2024-03-01",
434-
packages = "20240829.4", backport = 28,
434+
packages = "20240829.4", backport = 29,
435435
baselineSnapshotHash = "d13ce2f4a0ade2e09047b469874dacf4d071ed3558fec4c26f8d0b99d95f77b5")
436436
$impliedByAfterDate(name = "pythonWorkersDevPyodide", date = "2000-01-01");
437437
# Enables Python Workers. Access to this flag is not restricted, instead bundles containing
@@ -680,7 +680,7 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
680680
$compatEnableFlag("python_workers_20250116")
681681
$experimental
682682
$pythonSnapshotRelease(pyodide = "0.27.1", pyodideRevision = "2025-01-16",
683-
packages = "20250324.1", backport = 16,
683+
packages = "20250324.1", backport = 17,
684684
baselineSnapshotHash = "TODO");
685685

686686
requestCfOverridesCacheRules @72 :Bool

src/workerd/server/tests/python/durable-object/worker.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ async def on_fetch(self, req, env, ctx):
1717
async def no_args_method(self):
1818
return "value from python"
1919

20+
async def args_method(self, arg):
21+
return "value from python " + arg
22+
2023

2124
async def test(ctrl, env, ctx):
2225
id = env.ns.idFromName("A")
@@ -30,7 +33,8 @@ async def test(ctrl, env, ctx):
3033
second_resp_data = await second_resp.text()
3134
assert second_resp_data == "hello from python 2"
3235

33-
# TODO: Python effectively calls this via `obj.no_args_method.apply(obj, [])` which causes
34-
# a DataCloneError to occur. This may be a JS RPC bug that we will need to fix.
35-
# custom_resp = await obj.no_args_method()
36-
# assert custom_resp == "value from python: 42"
36+
no_arg_resp = await obj.no_args_method()
37+
assert no_arg_resp == "value from python"
38+
39+
arg_resp = await obj.args_method("test")
40+
assert arg_resp == "value from python test"

0 commit comments

Comments
 (0)