tortoise / tortoise/tortoise-orm
Inconsistent (and undocumented) length validators behaviour
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
Validators (introduced by ver. 0.16.19) breaks compatibility with previous max_length field property.
MaxLengthValidator raises exception if field is NULL.
Even worse the MaxLengthValidator is automatically applied to any CharField (because max_length is mandatory) so a nullable varchar couldn't be used anymore.
To Reproduce
Declare a CharField with any max_length and load a database row with NULL field.
Expected behavior
In (almost) any sql database implementation you can declare a field nullable with a max length so MaxLengthValidator should consider length ==0 for a null field.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at MaxLengthValidator and the CharField handling described in the issue, then reproduce the case with a nullable CharField whose database value is NULL. Done means the validator preserves compatibility with nullable fields by treating NULL as length 0, with coverage for the reported reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100