TimeField skips validators for timedelta values

Đang mở
#2,404 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

@IlyaKhalafi đang làm issue này rồi.

Từ ngày 5/11/2026.

  • #2405 của @IlyaKhalafi — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
databases

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
5.6k
Fork
543
Merge trung bình
4 ngày 7 giờ
Pull request đã merge (30 ngày)
31

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tortoise/tortoise-orm

Tất cả issue của tortoise/tortoise-orm

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.