The Django REST Framework uses serializers to serialize (output) and deserialize (input) data.
It's hard to say if you are serializing or deserializing your data in your case, but you will find problems with both, so I will give you an answer for both cases.
When deserializing data, you must pass the data for deserialization using the data keyword argument and (optionally) the instance to update using the instance keyword argument.
serializer = TestSerializer(data=s.get_results()) if serializer.is_valid(): data = serializer.data
This should work as expected, up to calling .data in the serializer. This is because the .data call will serialize the data object again, based on a temporary instance, which you'll learn below, still remains a problem.
It is important to note that when deserializing data, the required=False parameter will prevent the Django REST Framework from requiring this field to be present.
When serializing data, you need to pass a complete representation of the object using the instance keyword argument, which is also the first positional argument. The Django REST Framework expects the object to be passed will have all the fields you request, even if they are null ( None ) or empty. The required=False argument does nothing, because we serialize the data. Therefore, you need to make sure that the dictionary (or comparable object) is passed with all the keys that are required for the serializer.
There is a special case when an object is deserialized and then serialized using the same object. In this case, the base object that was created must still have an optional field, even if the input did not provide it.
source share