Open Crocmagnon opened 5 years ago
Very strange... I managed to have the expected result in my first query this morning, then everything falls apart in the RecursionError
I filed.
EDIT : So, more info about my dev (and prod) environment : I'm running Django behind IIS on Windows (😢)
I can confirm that after a reboot I'm getting the expected result once and then it goes back to recursion error. In fact, if I kill the Python process and make another request, IIS creates another one and gives me the expected result, then subsequent requests end up in RecursionError.
I never saw anything like that. Do you have any idea ? Maybe it has something to do with the process being kept alive ?
Here are more insights:
I tried creating a small test project to reproduce the issue using the example code I provided in the original post but I was unable to. Everything worked flawlessly using manage.py runserver
So I decided to give a try and spin up my dev environment with runserver
too.
Now I'm getting a TypeError [...] cannot serialize _io.BufferedReader
Ok, I managed to track it down to a custom __init__
method I have on the ClientSerializer
.
Here's a project that reproduces this issue: https://github.com/Crocmagnon/demo-recursion-error-drf-ff
The culprit seems to be there: https://github.com/Crocmagnon/demo-recursion-error-drf-ff/blob/master/api/serializers.py#L22-L27
EDIT:
I need to filter some fields on the ProjectSerializer
based on user permissions. Do you have any good idea of how I could do that ? I updated the example project to show how I currently do this, which requires the context to be passed to the serializer: https://github.com/Crocmagnon/demo-recursion-error-drf-ff/blob/master/api/serializers.py#L10-L17
I'm facing a RecursionError when querying a subset of fields that should not make recursion at all.
Here are some simplified models and serializers:
I queried my endpoint like this:
The expected result would be:
Instead, I'm getting a RecursionError (see below). Did I miss something ? I understand that since I'm requesting to expand the projects and the projects themselves have a reference to the clients, but given the
fields
input, I feel like this should not fall in recursion.