Disable validation of annotations #1747
Closed
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
Field.to_python_value
with thevalidate
argument with the default valueTrue
which regulates whether validation should be run.Field
and overrodeto_python_value
because its signature changedMotivation and Context
When an arithmetic expressions on a model field is used in annotations, the field's
to_python_value
is used to process the database value.to_python_value
is running validations by default and if the result of aggregation function doesn't pass field's validation, an exception happens.will cause
tortoise.exceptions.ValidationError: max_value: Value should be less or equal to 20.0
Other ideas
At the moment the validation is being run when the object is being loaded from the database, for instance, here and here. Does it really need to happen? The introduction of the
validate
argument can be used to disable validation in these cases.How Has This Been Tested
Checklist: