deserialize mutates the caller's dictionary by calling pop().
まだ誰も着手していません。
評価
調査の方向性
まず、Issueで入力辞書を変更すると指摘されているComplexTypeMetaDataMixin.deserialize、BasicTypeMetaDataMixin.deserialize、EnumWithMetaMixin.deserializeを読みます。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
- 平均マージ
- 3日 8時間
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
follow-up
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
modelscope/modelscope#1833 ·
メンテナーはふだん 1 日以内に返信
-
ocr_data_to_elements() raises AttributeError when a layout element is a List対応中かも @Eapp1e が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
Unstructured-IO/unstructured#4616 ·
メンテナーはふだん 1 日以内に返信