UUIDField skips configured validators when writing values

Đang mở
#2,407 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 6/11/2026.

  • #2408 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
25/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
database

Hướng nghiên cứu

Read the UUIDField implementation and compare its to_db_value behavior with field types that run configured validators. Start with a regression test for the direct conversion and database writes, including that nullable fields skip validators for None. Done means invalid UUIDs raise ValidationError on writes while valid values convert as expected; an open pull request (#2408) is already linked.

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

Mô tả

UUIDField.to_db_value converts the value to a string without running its configured validators. This also lets invalid values through model creation, saves and queryset updates.

from uuid import uuid1
from tortoise import fields
from tortoise.exceptions import ValidationError
from tortoise.models import Model

def require_v4(value):
    if value.version != 4:
        raise ValidationError('UUID must be version 4')

field = fields.UUIDField(validators=[require_v4])
field.to_db_value(uuid1(), Model)  # returns a string without raising

Expected behavior is to run field validation before converting the value, consistent with other field types. Nullable fields should still skip validators for None.

Reproduced on current develop with Python 3.14 and SQLite. Both a direct field regression and a database-write regression fail because validation does not run.

Upstream commit 5797ac34b4a13b94b3dfc1b69aaf81d032cfcb4d.

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.