A Pydantic validator never returns a value, so the field is set to None
What it finds
The value a field validator returns replaces the field's value. A validator that only checks and raises, but falls off its end, makes every valid input None. It returns the value it was given, changed or not.
From the rule's source, validator_returns_nothing.rs.
from pydantic import BaseModel, field_validator class M(BaseModel): x: int @field_validator("x") @classmethod def positive(cls, v):tx0 reports: this validator returns nothing, so the field becomes None if v < 0: raise ValueError("negative") @field_validator("x") @classmethod def ok(cls, v): if v < 0: raise ValueError("negative") return v Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:validator-returns-nothing" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:validator-returns-nothing] reason="..."tx0 explain tx0/python:validator-returns-nothing shows the same in the terminal. Found a false positive? Report it.