Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

deserialize mutates the caller's dictionary by calling pop().

オープン 初心者向け
#52 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

まず、Issueで入力辞書を変更すると指摘されているComplexTypeMetaDataMixin.deserialize、BasicTypeMetaDataMixin.deserialize、EnumWithMetaMixin.deserializeを読みます。ComplexTypeMetaDataMixinとBasicTypeMetaDataMixinに含まれる回帰テストを実行し、その後EnumWithMetaMixinも調べます。deserializeの呼び出しを通じて、各メソッドが@で始まるキーを含め、呼び出し元の辞書を保持できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Bug Report

Steps to Reproduce:
  1. Build a dict representing a serialised Rune object, including @-prefixed
    metadata keys (e.g. {"@type": "...", "@data": "..."}).
  2. Pass the dict to ComplexTypeMetaDataMixin.deserialize,
    BasicTypeMetaDataMixin.deserialize, or EnumWithMetaMixin.deserialize.
  3. 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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

finos/rune-python-runtime のほかの issue

finos/rune-python-runtime の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。