Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

deepcopy of DateWithMeta / TimeWithMeta / DateTimeWithMeta raises ValueError

Aperta Adatta ai principianti
#50 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia leggendo le definizioni di DateWithMeta, TimeWithMeta e DateTimeWithMeta in rune/runtime/metadata, in particolare new e serialise_meta. Riproduci l’errore segnalato con copy.deepcopy, poi verifica come ogni classe gestisce la copia. Il lavoro è concluso quando le copie superficiali e profonde mantengono il valore e i metadati senza sollevare ValueError; l’issue non indica alcun file di test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Report

Steps to Reproduce:
  1. Create a DateWithMeta (or TimeWithMeta / DateTimeWithMeta) instance.
  2. Call copy.deepcopy() on it — this occurs internally whenever
    _clone_for_write or model_copy(deep=True) is used on an object that
    contains a date/time-with-meta field.
Expected Result:

A new DateWithMeta (or TimeWithMeta / DateTimeWithMeta) is returned with
the same value and metadata as the original.

Actual Result:

ValueError is raised:
"DateWithMeta can be instantiated only with one of the following type(s):
(<class 'datetime.date'>, <class 'str'>), however the value is of type
<class 'bytes'>."

Environment:

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

Additional Context:

datetime.date.reduce_ex returns a raw-bytes representation for pickling.
Python's deepcopy uses this protocol, calling
DateWithMeta.new(DateWithMeta, bytes). DateWithMeta.new calls
_check_type, which rejects bytes. The same crash affects TimeWithMeta and
DateTimeWithMeta.
Fix: add deepcopy (and copy) overrides to each class that reconstruct
via cls(value, **self.serialise_meta()), bypassing the C-level pickling path.

import copy
import datetime

import pytest

from rune.runtime.metadata import DateWithMeta, TimeWithMeta, DateTimeWithMeta

def test_r4_datewithmeta_deepcopy_raises():
    '''copy.deepcopy(DateWithMeta(...)) raises ValueError because
    datetime.date.__reduce_ex__ passes raw bytes to DateWithMeta.__new__,
    which _check_type rejects.'''
    d = DateWithMeta('2024-01-15')
    with pytest.raises(ValueError, match='bytes'):
        copy.deepcopy(d)


def test_r4_timewithmeta_deepcopy_raises():
    '''copy.deepcopy(TimeWithMeta(...)) raises ValueError for the same reason.'''
    t = TimeWithMeta('10:30:00')
    with pytest.raises(ValueError, match='bytes'):
        copy.deepcopy(t)


def test_r4_datetimewithmeta_deepcopy_raises():
    '''copy.deepcopy(DateTimeWithMeta(...)) raises ValueError for the same reason.'''
    dt = DateTimeWithMeta('2024-01-15T10:30:00')
    with pytest.raises(ValueError, match='bytes'):
        copy.deepcopy(dt)
Lingua principale
Python
Stelle
0
Fork
4
Merge medio
1g 11h
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di finos/rune-python-runtime

Tutte le issue di finos/rune-python-runtime

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.