Hi.

I've found that UniqueTogetherValidator updates data while validation.
Assume:
* I have model with unique_together = ("field_a", "field_b")
* I have model serialiser based on it. And it has UniqueTogetherValidator
* I try to do partial update of existed instance.  And I try to update 
"field_c"

I expect that validated_data will contains only the field "filed_c". But it 
also contains fields "filed_a" and "field_b".

I've found that this validator save fields into "attrs" dictionary. And 
this "attrs" will became validated_data at end.
https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/validators.py#L139

    def filter_queryset(self, attrs, queryset):
        """
        Filter the queryset to all instances matching the given attributes.
        """
        # If this is an update, then any unprovided field should
        # have it's value set based on the existing instance attribute.
        if self.instance is not None:
            for field_name in self.fields:
                if field_name not in attrs:
                    attrs[field_name] = getattr(self.instance, field_name)

        # Determine the filter keyword arguments and filter the queryset.
        filter_kwargs = {
            field_name: attrs[field_name]
            for field_name in self.fields
        }
        return qs_filter(queryset, **filter_kwargs)


I don't know If it is a bug or feature.
But it is not good for me.

What do you think? Should I open issue? 

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to