Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depth Infinite Recursion on ModelSerializer #2913

Closed
mattbrandman opened this issue May 6, 2015 · 1 comment
Closed

Depth Infinite Recursion on ModelSerializer #2913

mattbrandman opened this issue May 6, 2015 · 1 comment

Comments

@mattbrandman
Copy link

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

@tomchristie
Copy link
Member

Resolved in master by #2798.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants