TimeField skips validators for timedelta values

オープン
#2,404 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@IlyaKhalafi がすでに取り組んでいます。

2026年11月5日 から。

  • #2405 @IlyaKhalafi による — オープン

評価

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

調査の方向性

Start by reading TimeField.to_db_value() in the field implementation and the existing validation tests. Reproduce the issue with the provided negative timedelta, then check that configured validators run and a valid timedelta is returned unchanged. The linked pull request #2405 is already open, so this work is underway.

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

説明

TimeField.to_db_value() returns timedelta values before calling the configured validators. These values are supported by the field and are returned by MySQL time columns.

from datetime import timedelta
from tortoise.fields import TimeField
from tortoise.exceptions import ValidationError

def reject_negative(value):
    if value < timedelta():
        raise ValidationError("negative time")

field = TimeField(validators=[reject_negative])
field.to_db_value(timedelta(hours=-1), object())

This returns the negative timedelta without raising on current develop. The field's normal validation path is skipped entirely for that type.

Removing the early return should let the existing validation call run while preserving the timedelta value. Reproduced directly on Python 3.14 without a database connection. A regression also checks that a valid timedelta is returned unchanged.

主要言語
Python
スター
5.6k
フォーク
540
平均マージ
4日 4時間
マージ済み PR(30日)
32

環境構築

はじめの一歩

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

tortoise/tortoise-orm のほかの issue

tortoise/tortoise-orm の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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