mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Fix ModelSerializer.get_validators with Meta property.
The Meta subclass is sometimes a Field class and has the property `validators`. Properties require an instance otherwise the property object is returned which will result in an error when trying `validators[:]`.
This commit is contained in:
parent
3ef3fee926
commit
82d955d345
|
@ -1372,9 +1372,14 @@ class ModelSerializer(Serializer):
|
||||||
Determine the set of validators to use when instantiating serializer.
|
Determine the set of validators to use when instantiating serializer.
|
||||||
"""
|
"""
|
||||||
# If the validators have been declared explicitly then use that.
|
# If the validators have been declared explicitly then use that.
|
||||||
validators = getattr(getattr(self, 'Meta', None), 'validators', None)
|
meta = getattr(self, 'Meta', None)
|
||||||
if validators is not None:
|
if meta is not None:
|
||||||
return validators[:]
|
validators = getattr(meta, 'validators', None)
|
||||||
|
if isinstance(validators, property):
|
||||||
|
validators = getattr(meta(), 'validators', None)
|
||||||
|
|
||||||
|
if validators is not None:
|
||||||
|
return validators[:]
|
||||||
|
|
||||||
# Otherwise use the default set of validators.
|
# Otherwise use the default set of validators.
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user