mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-31 18:40:07 +03:00
Prevent validator's context to be used by another serializer
Fixes encode/django-rest-framework#5760
This commit is contained in:
parent
2ce30ddc7a
commit
a1322ca441
|
@ -251,6 +251,7 @@ class CreateOnlyDefault(object):
|
|||
def set_context(self, serializer_field):
|
||||
self.is_update = serializer_field.parent.instance is not None
|
||||
if callable(self.default) and hasattr(self.default, 'set_context') and not self.is_update:
|
||||
self.default = copy.deepcopy(self.default)
|
||||
self.default.set_context(serializer_field)
|
||||
|
||||
def __call__(self):
|
||||
|
@ -475,6 +476,7 @@ class Field(object):
|
|||
raise SkipField()
|
||||
if callable(self.default):
|
||||
if hasattr(self.default, 'set_context'):
|
||||
self.default = copy.deepcopy(self.default)
|
||||
self.default.set_context(self)
|
||||
return self.default()
|
||||
return self.default
|
||||
|
@ -532,6 +534,7 @@ class Field(object):
|
|||
errors = []
|
||||
for validator in self.validators:
|
||||
if hasattr(validator, 'set_context'):
|
||||
validator = copy.deepcopy(validator)
|
||||
validator.set_context(self)
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue
Block a user