Serialisation fails with pydantic 2.14: wrap serialisers pass SerializationInfo as index_key
評估
研究方向
兩處有問題的呼叫分別位於 src/rune/runtime/base_data_class.py 的第 110 行,即呼叫 serializer(self, info) 的地方,以及 src/rune/runtime/metadata.py 的第 692 行,即呼叫 handler(obj.enum_instance, info) 的地方。請使用 issue 中的程式片段在 pydantic 2.14.1 上重現問題,然後修改這兩處呼叫,使 handler 只接收值。完成的標準是:該程式片段能印出預期的 JSON,且倉庫測試套件中失敗的 15 個測試全部通過。
由索引模型根據 Issue 內容生成。
描述
Bug Report
With pydantic 2.14, serialising any BaseDataClass fails. pyproject.toml allows any pydantic >=2.10.3, so a fresh install gets 2.14.1 and breaks.
Two wrap serialisers pass pydantic's SerializationInfo as the second positional argument of the handler they are given. That argument is index_key (def __call__(self, input_value, index_key: int | str | None = None, /)). Up to 2.13, pydantic accepted whatever was passed there; 2.14 checks its type:
src/rune/runtime/base_data_class.py:110:serializer(self, info)src/rune/runtime/metadata.py:692:handler(obj.enum_instance, info)
Steps to Reproduce:
pip install rune.runtime==2.2.1 pydantic==2.14.1- Run:
from rune.runtime.base_data_class import BaseDataClass class A(BaseDataClass): value: int | None = None print(A(value=1).rune_serialize())
Expected Result:
{"@type":"__main__","@model":"__main__","@version":"0.0.0","value":1}, which is what pydantic 2.12.5 and 2.13.4 produce.
Actual Result:
pydantic_core._pydantic_core.PydanticSerializationError: Error serializing to JSON: PydanticSerializationError: Error calling function `_serialize_refs`: TypeError: 'index_key' is expected to be an integer or a string, got 'SerializationInfo(include=None, exclude=None, context=None, mode='json', by_alias=False, exclude_unset=True, exclude_defaults=True, exclude_none=False, exclude_computed_fields=False, round_trip=False, serialize_as_any=False)'
On main with pydantic 2.14.1, 15 tests in this repo's suite fail this way.
Environment:
rune.runtime 2.2.1 and main (b0fa1cd), pydantic 2.14.1 / pydantic-core 2.50.1, Python 3.12, macOS.
Additional Context:
The fix is to call the handler with the value only. The rune-python-generator Python unit tests (features/serialization/) hit the same error, because generated packages also leave pydantic unpinned.
- 主要語言
- Python
- 星號
- 0
- 分支
- 4
- 平均合併
- 8 小時 25 分鐘
- 30 天內合併 PR
- 3
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
finos/rune-python-runtime 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 84/100
finos/rune-python-runtime#43 ·
-
難度 5/5 一週以上 新手友好度 35/100
finos/rune-python-runtime#42 ·
-
難度 3/5 1-2 天 新手友好度 62/100
finos/rune-python-runtime#27 ·
-
難度 5/5 一週以上 新手友好度 25/100
finos/rune-python-runtime#16 ·
-
難度 4/5 3-5 天 新手友好度 35/100
finos/rune-python-runtime#15 · 1 則留言 ·
查看 finos/rune-python-runtime 的全部 Issue
相似的 Issue
-
customer-reported question
難度 2/5 1-3 小時 新手友好度 62/100
Azure/azure-sdk-for-python#49548 · 1 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
btclib-org/btclib-wallet#409 ·
維護者通常 1 天內回覆
-
Phase 2 PSA Capability & Career Profile
難度 2/5 1-3 小時 新手友好度 62/100
bcgov/digital-journeys#2310 ·
-
bug good first issue
難度 2/5 1-3 小時 新手友好度 78/100
fastmachinelearning/hls4ml#1582 ·
維護者通常 3 天內回覆
-
Sort models未關閉enhancement good first issue
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 1 天內回覆