Do not validate when loading from the db #1750
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
Checklist: