validated_data empty when is_valid() is True

15 views
Skip to first unread message

David Binetti

unread,
Aug 20, 2019, 8:40:18 AM8/20/19
to Django REST framework
I'm perplexed and can't figure out what I'm missing.  I've stripped a ModelSerializer down to just the PK (a UUID) and am trying to create a serialized object through the data= kwarg.  I then call is_valid() which returns true, but the validated_data is empty.  what am I doing wrong?

```
class GroupSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = [
            'id',
        ]

In [17]: data = {'id': 'fffd128a-8fc0-4487-b297-f952c38c1d09'}  

    ...: serialized = GroupSerializer(data=data)  

    ...:                                                                               


In [18]: serialized.initial_data                                                       

Out[18]: {'id': 'fffd128a-8fc0-4487-b297-f952c38c1d09'}


In [19]: serialized.is_valid()                                                         

Out[19]: True


In [20]: serialized.validated_data                                                     

Out[20]: OrderedDict()

```

Carlton Gibson

unread,
Aug 20, 2019, 8:45:44 AM8/20/19
to django-res...@googlegroups.com
Can you print(serialized) in the shell?

Auto generated ID fields are read-only I think. 

--
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-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/7b9fa6d5-09d2-4a9e-81c2-b782ae809f85%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages