Closed henadzit closed 3 weeks ago
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
tortoise/backends/sqlite/executor.py | 3 | 4 | 75.0% | ||
<!-- | Total: | 5 | 6 | 83.33% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
tortoise/backends/sqlite/executor.py | 1 | 77.14% | ||
<!-- | Total: | 1 | --> |
Totals | |
---|---|
Change from base Build 11529966516: | -0.02% |
Covered Lines: | 5974 |
Relevant Lines: | 6598 |
@abondar, would love to hear your feedback on this one!
Description
validate
calls fromField.to_python_value
, effectively, removing validation of objects when they are loaded from the databaseMotivation and Context
None of the ORMs that I checked validate records when loading them from the database:
I do not see a reason why validating the record on loading should be a default behavior. I can see that you might want to do it in some cases but you can always call
.validate
explicitly. But I can imagine the issue where you add a new validator, run a data migration to fix the data but while the migration is being run, the reads are failing.I also ran a benchmark where I was loading 100
testmodels.ValidatorModel
records from the database and on average not running validation is ~5% faster for a model with many validators. I do not think at all that this is a decisive argument but something to keep in mind.How Has This Been Tested?
from tortoise import Tortoise, fields, run_async from tortoise.functions import Sum from tortoise.models import Model from tortoise.expressions import F, Q from tortoise.validators import MinValueValidator
class Deal(Model): test = fields.IntField() broker_payed_money = fields.FloatField(default=0, validators=[MinValueValidator(0)])
async def main():
Initializing Tortoise and creating the schema
run_async(main())