TimeField skips validators for timedelta values

Aperta
#2,404 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@IlyaKhalafi ci sta già lavorando.

Dal 5/11/2026.

  • #2405 di @IlyaKhalafi — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
databases

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
5.6k
Fork
540
Merge medio
4g 4h
PR unite (30g)
32

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tortoise/tortoise-orm

Tutte le issue di tortoise/tortoise-orm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.