Fix: Add Unique..., BaseUniqueForValidators type add - #709
Conversation
…ator to validators
|
|
||
| Validator: TypeAlias = Callable[[_V], None] | ContextValidator[_V] | ||
| Validator: TypeAlias = ( | ||
| Callable[[_V], None] | ContextValidator[_V] | UniqueValidator | UniqueTogetherValidator | BaseUniqueForValidator |
There was a problem hiding this comment.
This change shouldn't be necessary.
-
UniqueValidatorshould already be accepted because it conforms to theContextValidatorprotocol. -
UniqueTogetherValidatorandBaseUniqueForValidatorshould in fact not be accepted forFooField(validators=[...])valueThese can only be used in a
SerializerMetaclass, e.g. see example code in documentation https://www.django-rest-framework.org/api-guide/validators/#uniquetogethervalidator
But this was quite tricky to figure out, it would help if it was explained in a comment.
And the Validator type alias would be better called FieldValidator.
There was a problem hiding this comment.
As I understand, what was asked in the original issue
was actually different. The Serializer class inherits a validators property from Field class (@property def validators(self) -> list[Validator[_VT]] from Field class.
What it doesn't account for is that in case of Serializer class, validators in that case actually can include UniqueTogetherValidator and others.
intgr
left a comment
There was a problem hiding this comment.
Doh! I wrote these comments a week ago, but forgot to submit the review. Sorry!
…ator to validators
I have made things!
Serializer.validatorsnow has theUnique...validators type added to it.Related issues
Format is:
I'm a newbie developer.
If you have any feedback, just write it here.
It can be whatever you want!