✅ Add tests for body fields aliases #14293
Draft
+2,622
−0
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.
Test Coverage Summary
Tests for Pydantic V2 include:
Form(alias=...)+ the same for form modelForm(validation_alias=...)+ the same for form modelForm(alias=..., validation_alias=...)+ the same for form modelForm(alias=X, validation_alias=X)Each of test cases (except workaround) covers different field types:
strfieldstrfieldlistfieldlistfieldEach of test cases covers different parameter types:
FormfieldFormfield declared as model (think about adding tests foralias_generator,populate_by_name,alias_priority,alias_choices)FilefieldFilefield declared as model (TODO: add tests)Bodyfield (TODO: add tests)Bodyfield declared as model (TODO: add tests)For each type of parameter declaration, the following is checked:
aliasvalidation_alias(if specified)Tests for Pydantic V1
Tests for Pydantic V1 duplicate tests for V2, excluding all tests with
validation_alias(it's not implmented for V1 and I don't think we need to add this)Current situation with alias support
Currently tests expose several issues with Pydantic V2:
alias- for Form\File fields works partially - isn't reflected in schemavalidation_alias- for Form\File fields is reflected in schema, but doesn't workTypeErrorvalidation_aliasfor List Fields fails due to some bug ("Input should be a valid list","input":"456")Currently tests expose 1 issue with Pydantic V1:
stringinstead ofanyOf) - TODO: investigate