-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
DictField and ListField error if child is a serializer with many=True #5384
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
Comments
Hi @warrd is the issue here not with adding the A ListField has a child. Let’s say it’s a CharField for example. Here what sense does the So why are you trying to add the many? What are you looking for there? My first thought then is perhaps we need a guard raising an error if child has the |
Just hit this as well when upgrading from 3.6.0 --> 3.6.3. The issue is that its raising an error that it previously did not raise :). I changed all the many=True to many=False and this did raise quite a few errors, so there definitely is at least some breaking change going on here. |
In our case we have definitions like this:
which translate into roughly this:
|
was able to get it to work by changing to this:
So my guess is that @warrd could do this:
still not good for a minor version bump, but workable. |
@NickStefan Any chance you could git bisect this to work out where the change was introduced? |
@NickStefan cheers for the suggestion, that's exactly what we ended up doing :) @carltongibson I linked to where the change was introduced in my original comment, here it is again: https://github.com/encode/django-rest-framework/pull/4222/files#diff-80f43677c94659fbd60c8687cce68eafR538 |
@warrd Sorry, yes. Thanks! |
Hi, same problem with DictField. I have tried with the ListField approach but getting the same error. |
Dragging up a bit of an old issue here but I had this same issue recently when upgrading from an older version of drf. This was happening on a nested serializer that was re-defining only a subset of it's fields as class attributes and also specifying the # Throws the error documented in this issue
class SomeSerializer(serializers.ModelSerializer):
some_many_field = SomeManySerializer(many=True)
class Meta:
model = SomeModel
fields = ['some_many_field', 'some_other_field'] It hadn't been a problem in earlier versions of drf without the explicit # Works
class SomeSerializer(serializers.ModelSerializer):
some_many_field = SomeManySerializer(many=True)
some_other_field = serializers.CharField(required=False)
class Meta:
model = SomeModel
fields = ['some_many_field', 'some_other_field'] I haven't done a deep dive to see why this is the case. |
It looks like this could be addressed adding a |
Closing as (very) stale. |
The following example fails during the
bind
method:Here is a partial stacktrace:
When
many=False
this serializer works as expected.The problem is introduced by #4222, which assumes the parent of
ListSerializer
is a serializer instance, which would mean the field was declared on a serializer class rather than as a child argument to aDictField
/ListField
. Is this a fair assumption to make?The documentation for
DictField
andListField
only mention aField
instance is expected for thechild
argument.Serializer
is a subclass ofField
so I think it is fair to assume a serializer can be used here.Checklist
master
branch of Django REST framework.The text was updated successfully, but these errors were encountered: