-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
It is possible to run into a recursion loop that maxes the recursion limit due to ModelSerializer not subtracting one from nested_depth when it creates a NestedSerializer.
Given a case where two serializers are mapped to models that have circular dependencies called A & B respectively, when field.to_representation(attribute) is called on the field of one model that points to that other model a Nested Serializer is created and is used in the next loop of to_representation. Through the self.fields.values() call all the fields needed are evaluated but the field linking those two models due to depth not changing in the Nested Serializer creates another nested serializer with no depth change and the loop starts again.
This will continue until django reaches max recursion in to_reprsentation or all memory is consumed. I believe the easiest fix is to add
depth = nested_depth - 1 on line 1041 in serializers.py. such as is done for the hyperlinkedmodelserializer