deserialize mutates the caller's dictionary by calling pop().
還沒有人認領這個 Issue。
評估
研究方向
首先閱讀 ComplexTypeMetaDataMixin.deserialize、BasicTypeMetaDataMixin.deserialize 和 EnumWithMetaMixin.deserialize,issue 指出這些方法會修改輸入字典。執行隨附的 ComplexTypeMetaDataMixin 和 BasicTypeMetaDataMixin 回歸測試,接著也檢查 EnumWithMetaMixin。完成標準是每個方法在 deserialize 呼叫過程中都保留呼叫者的字典,包括以 @ 開頭的鍵。
由索引模型根據 Issue 內容生成。
描述
Bug Report
Steps to Reproduce:
- Build a dict representing a serialised Rune object, including @-prefixed
metadata keys (e.g. {"@type": "...", "@data": "..."}). - Pass the dict to ComplexTypeMetaDataMixin.deserialize,
BasicTypeMetaDataMixin.deserialize, or EnumWithMetaMixin.deserialize. - Inspect the original dict after the call.
Expected Result:
The original dict is unchanged; deserialize works on its own copy.
Actual Result:
The @-prefixed keys are absent from the original dict after the call:
ComplexTypeMetaDataMixin.deserialize calls obj.pop(k) for every @-key.
BasicTypeMetaDataMixin.deserialize and EnumWithMetaMixin.deserialize call
obj.pop('@data').
Re-using the same dict for a second deserialize call (e.g. round-trip or
batch processing) therefore fails.
Environment:
rune-python-runtime 2.2.2, pydantic 2.14.1, Python 3.11
Additional Context:
All three deserialize methods operate on the input dict directly rather than
a shallow copy.
Fix: replace pop() calls with dict comprehensions / dict.get() operating on a
local copy so the caller's dict is never modified.
import pytest
import finos._bundle
from finos.cdm.base.staticdata.asset.common.AssetTypeEnum import AssetTypeEnum
from finos.cdm.base.staticdata.asset.common.Security import Security
from rune.runtime.metadata import DateWithMeta
def test_r6_complex_type_deserialize_does_not_mutate_dict():
'''ComplexTypeMetaDataMixin.deserialize should not pop @-keys from the
caller's dict. After the call, @type must still be present.'''
input_dict = {
'@type': 'finos.cdm.base.staticdata.asset.common.Security',
'assetType': AssetTypeEnum.SECURITY.value,
}
original_type_key = input_dict.get('@type')
try:
Security.deserialize(input_dict, set())
except Exception:
pass # other errors are acceptable; we only check dict mutation
assert '@type' in input_dict, (
'deserialize mutated the caller\'s dict: @type was popped'
)
assert input_dict['@type'] == original_type_key
def test_r6_basic_type_deserialize_does_not_mutate_dict():
'''BasicTypeMetaDataMixin.deserialize should not pop @data from the
caller's dict. After the call, @data must still be present.'''
import datetime
input_dict = {'@data': '2024-01-15'}
try:
DateWithMeta.deserialize(
input_dict,
lambda x: x,
(datetime.date, str),
set(),
)
except Exception:
pass
assert '@data' in input_dict, (
'deserialize mutated the caller\'s dict: @data was popped'
)
- 主要語言
- Python
- 星號
- 0
- 分支
- 4
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 3
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
finos/rune-python-runtime 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
finos/rune-python-runtime#51 ·
-
難度 2/5 1-3 小時 新手友好度 76/100
finos/rune-python-runtime#50 ·
-
難度 2/5 1-3 小時 新手友好度 76/100
finos/rune-python-runtime#48 ·
-
難度 1/5 1 小時以內 新手友好度 84/100
finos/rune-python-runtime#47 ·
-
難度 2/5 1-3 小時 新手友好度 84/100
finos/rune-python-runtime#43 ·
查看 finos/rune-python-runtime 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 72/100
slavakurilyak/awesome-ai-agents#845 ·
維護者通常 1 天內回覆
-
tests: pin that the atomic writers in utils/paths.py stage the temporary file in the target's directory可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉difficulty:2 enhancement good first issue
難度 1/5 1-3 小時 新手友好度 92/100
MakazhanAlpamys/Soup#2178 ·
維護者通常 1 天內回覆
-
[BUG] dcg.waggr permutation p-values are folded twice, so near-zero scores get the smallest p-values未關閉
難度 2/5 1-3 小時 新手友好度 75/100
scverse/rapids-singlecell#854 ·
維護者通常 1 天內回覆
-
Slang input: int8_t4_packed and uint8_t4_packed are copied into CrossGL可能已有人在做 @ninglinLiu 今天認領。 未關閉area:frontend backend:slang bug direction:input
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 13 天內回覆