Skip to content

Depth Infinite Recursion on ModelSerializer #2913

@mattbrandman

Description

@mattbrandman

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy