You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fields of a Serializerclass field are skipped if root serializer is partial #2585
Hrm. This isn't really the intended usage - so we may need to think about this. Partial is only intended as an argumet when instantiating a serializer instance, rather than declaring a nested serializer as a field.
it only deals with normal cases where the entire hierarchy is required or not. however, there will be such cases where if nested serializer specified, all its fields will be required otherwise it is not valid. Like my case, where location missing all or one attribute is considered invalid, still got validated, at the same time where I don't want to force it along with other fields such as username, email, etc.
class UserDetailSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('username', 'name', 'location', 'email')
I had a similar issue in which I wanted to validate nested resources that didn't have an id.
So basically the nested resources with no id should have a full validation. I've resolved with this mixin:
classValidatePartialWithoutIdMixin():
defrun_validation(self, data):
# if root is partial we should validate everything if there is no idparent=self.parentif'id'notindata:
self.parent=Noneres=super(ValidatePartialWithoutIdMixin, self).run_validation(data)
self.parent=parentreturnres
If deemed acceptable, the general idea of (re)configuring a nested serializer using kwargs could also be used to address nested validation issues like #2996 (related #2403).
That case is more complicated because it requires new behavior (orthogonal to partial), but it looks like the existing SkipField infrastructure could be coopted so it might not take much to add an appropriate flag/mode.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Activity
lovelydinosaur commentedon Feb 20, 2015
Hrm. This isn't really the intended usage - so we may need to think about this. Partial is only intended as an argumet when instantiating a serializer instance, rather than declaring a nested serializer as a field.
nourspace commentedon Feb 20, 2015
in this section:
http://www.django-rest-framework.org/api-guide/serializers/#dealing-with-nested-objects
it only deals with normal cases where the entire hierarchy is required or not. however, there will be such cases where if nested serializer specified, all its fields will be required otherwise it is not valid. Like my case, where location missing all or one attribute is considered invalid, still got validated, at the same time where I don't want to force it along with other fields such as username, email, etc.
lovelydinosaur commentedon Feb 20, 2015
Oh sure, I'm not saying that there might not be a valid case for this, just that it wasn't a use-case envisaged during the design.
patrick91 commentedon Jul 28, 2016
I had a similar issue in which I wanted to validate nested resources that didn't have an id.
So basically the nested resources with no id should have a full validation. I've resolved with this mixin:
claytondaley commentedon Nov 7, 2017
If deemed acceptable, the general idea of (re)configuring a nested serializer using kwargs could also be used to address nested validation issues like #2996 (related #2403).
That case is more complicated because it requires new behavior (orthogonal to partial), but it looks like the existing
SkipFieldinfrastructure could be coopted so it might not take much to add an appropriate flag/mode.stale commentedon Oct 19, 2025
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.