From 76ca55ad13d154c8cd164da9603130a87db9aa65 Mon Sep 17 00:00:00 2001 From: Gyeongjae Choi Date: Thu, 9 Jul 2026 19:36:38 +0900 Subject: [PATCH] fix: fix entropy patch for newer pydantic versions --- .../workerd-test/entropy-patches/worker.py | 4 ---- .../_workers_sdk_entropy_import_context.py | 22 +++++++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/cli/tests/workerd-test/entropy-patches/worker.py b/packages/cli/tests/workerd-test/entropy-patches/worker.py index 3bcf02c..1b0888b 100644 --- a/packages/cli/tests/workerd-test/entropy-patches/worker.py +++ b/packages/cli/tests/workerd-test/entropy-patches/worker.py @@ -21,10 +21,6 @@ async def noop(*args): class Default(WorkerEntrypoint): async def test(self): - if sys.version_info >= (3, 14): - # FIXME(soon): fix entropy patches for newer packages - return - os.chdir("/session/metadata/tests") args = [".", "-vv"] assert pytest.main(args) == 0 diff --git a/packages/runtime-sdk/src/_workers_sdk_entropy_import_context.py b/packages/runtime-sdk/src/_workers_sdk_entropy_import_context.py index 630b26a..06633b4 100644 --- a/packages/runtime-sdk/src/_workers_sdk_entropy_import_context.py +++ b/packages/runtime-sdk/src/_workers_sdk_entropy_import_context.py @@ -92,14 +92,22 @@ def pydantic_core_context(module): with allow_bad_entropy_calls(1): yield finally: - try: + validate_core_schema = getattr(module, "validate_core_schema", None) + if validate_core_schema is None: + # pydantic-core >=2.41 no longer exports validate_core_schema. Build a + # tiny validator instead so any lazy hash-map seeds are initialized + # before the snapshot is captured. with allow_bad_entropy_calls(1): - # validate_core_schema makes an ahash::AHashMap which makes - # another entropy call for its hash seed. It will throw an error - # but only after making the needed entropy call. - module.validate_core_schema(None) - except module.SchemaError: - pass + module.SchemaValidator({"type": "any"}) + else: + try: + with allow_bad_entropy_calls(1): + # validate_core_schema makes an ahash::AHashMap which makes + # another entropy call for its hash seed. It will throw an error + # but only after making the needed entropy call. + validate_core_schema(None) + except module.SchemaError: + pass @register_exec_patch("aiohttp.http_websocket")