TimeField skips validators for timedelta values

未关闭
#2,404 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

@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
派生
543
平均合并
4 天 17 小时
30 天内合并 PR
33

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tortoise/tortoise-orm 的其他 Issue

查看 tortoise/tortoise-orm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。