File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -401,6 +401,8 @@ def get_fields(self):
401401
402402 def _validate_unique_fields (self , validated_data ):
403403 for field_name in self ._unique_fields :
404+ if self .partial and field_name not in validated_data :
405+ continue
404406 unique_validator = UniqueValidator (self .Meta .model .objects .all ())
405407 try :
406408 # `set_context` removed on DRF >= 3.11, pass in via __call__ instead
Original file line number Diff line number Diff line change @@ -68,3 +68,13 @@ def test_create_update_failed(self):
6868 ctx .exception .detail ,
6969 {'child' : {'field' : ['This field must be unique.' ]}}
7070 )
71+
72+ def test_unique_field_not_required_for_partial_updates (self ):
73+ child = models .UFMChild .objects .create (field = 'value' )
74+ serializer = serializers .UFMChildSerializer (
75+ instance = child ,
76+ data = {},
77+ partial = True
78+ )
79+ self .assertTrue (serializer .is_valid ())
80+ serializer .save ()
You can’t perform that action at this time.
0 commit comments