Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

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

Ouverte Adaptée aux débutants
#52 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
78/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python
Domaine
backend

Piste de recherche

Commencez par lire ComplexTypeMetaDataMixin.deserialize, BasicTypeMetaDataMixin.deserialize et EnumWithMetaMixin.deserialize, que l’issue indique comme modifiant le dictionnaire d’entrée. Exécutez les tests de régression inclus pour ComplexTypeMetaDataMixin et BasicTypeMetaDataMixin, puis examinez également EnumWithMetaMixin. Le travail est terminé lorsque chaque méthode préserve le dictionnaire de l’appelant, y compris ses clés préfixées par @, lors des appels à deserialize.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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'
    )
Langage dominant
Python
Étoiles
0
Forks
4
Merge moyen
1 j 11 h
PR mergées (30 j)
3

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de finos/rune-python-runtime

Toutes les issues de finos/rune-python-runtime

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.