model_copy(deep=True) follows __rune_parent links, producing an attached copy instead of a detached subtree.

Offen
#49 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

@whawk46 arbeitet bereits daran.

Seit 30.10.2026.

  • #54 von @whawk46 — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
58/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend

Rechercherichtung

Start with rune/runtime/cow.py and the BaseDataClass definition, then inspect how model_copy(deep=True) handles dict and PARENT_PROP. Run the included regression test for _clone_for_write and check whether a deep copy omits the parent link while preserving the copied subtree. Done means the clone has no rune parent and deep nested graphs avoid copying their ancestors.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Bug Report

Steps to Reproduce:
  1. Build a parent–child object graph (any nested CDM types where fields are
    set via normal assignment, which calls _set_rune_parent).
  2. Call a generated Rune function that writes to a nested field — the function
    body calls _clone_for_write, which calls value.model_copy(deep=True).
  3. For a graph of depth d, observe O(d²) object allocations; for deep CDM
    graphs, observe RecursionError.
Expected Result:

_clone_for_write returns a detached copy with no __rune_parent (the clone is
independent of the original tree).

Actual Result:

model_copy(deep=True) uses copy.deepcopy on dict, which follows the
PARENT_PROP (__rune_parent) pointer up the tree. The clone retains the
original parent reference, and copies of the entire ancestor chain are made.

Environment:

rune-python-runtime 2.2.2, pydantic 2.14.1, Python 3.11

Additional Context:

cow.py _clone_for_write has no special handling for the back-link.
Fix: add a deepcopy override to BaseDataClass that excludes PARENT_PROP
so model_copy(deep=True) produces a detached subtree.

import pytest

import finos._bundle
from finos.cdm.base.staticdata.asset.common.Security import Security
from rune.runtime.cow import _clone_for_write

def test_r3_clone_for_write_copies_rune_parent():
    '''_clone_for_write(child) should produce a detached copy with no
    rune_parent.  Currently model_copy(deep=True) copies the parent link,
    so the clone remains attached to the original parent.'''
    parent = Security.model_construct()
    child = Security.model_construct()
    child._set_rune_parent(parent)

    assert child.get_rune_parent() is parent  # confirm setup

    clone = _clone_for_write(child)

    # A detached clone must not carry the original parent reference.
    # Bug: clone.get_rune_parent() returns the original parent object.
    assert clone.get_rune_parent() is None, (
        '_clone_for_write should produce a detached copy (no rune_parent); '
        f'got {clone.get_rune_parent()}'
    )
Vorherrschende Sprache
Python
Sterne
0
Forks
4
Ø Merge
1 T. 17 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus finos/rune-python-runtime

Alle Issues in finos/rune-python-runtime

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.