Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉 適合新手
#52 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
backend

研究方向

首先閱讀 ComplexTypeMetaDataMixin.deserialize、BasicTypeMetaDataMixin.deserialize 和 EnumWithMetaMixin.deserialize,issue 指出這些方法會修改輸入字典。執行隨附的 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
平均合併
1 天 11 小時
30 天內合併 PR
3

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

finos/rune-python-runtime 的其他 Issue

查看 finos/rune-python-runtime 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。