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

deepcopy of DateWithMeta / TimeWithMeta / DateTimeWithMeta raises ValueError

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

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

評価

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

調査の方向性

まず rune/runtime/metadata にある DateWithMeta、TimeWithMeta、DateTimeWithMeta の定義、特に new と serialise_meta を読んでください。copy.deepcopy で報告された失敗を再現し、各クラスがコピーをどのように処理するか確認してください。浅いコピーと深いコピーのどちらでも、ValueError を発生させずに値とメタデータが保持されれば完了です。issue ではテストファイルは指定されていません。

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

説明

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)
主要言語
Python
スター
0
フォーク
4
平均マージ
1日 11時間
マージ済み PR(30日)
3

環境構築

はじめの一歩

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

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

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

似ている issue

Python の issue をもっと見る

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

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