Assert fields in exclude are model fields#2319
Conversation
Sorry could you give the context for what code is giving you this stacktrace? What's the most minimal example of a model and serializer that reproduces it? |
class Channel(models.Model):
name = models.CharField(max_length=128)
class Subscription(models.Model):
channel = models.ForeignKey(Channel, related_name='subscribers')class ChannelSerializer(ModelSerializer):
class Meta():
model = Channel
exclude = ('subscribers', )Here I would have something like the following: exclude = ('subscribers',)
field_name = 'subscribers'
fields = ['id', 'name']I think that I had reverse relationships populated on 2.4.4, which is why I excluded it. In any case, if it's a field name not in the ones that the serializer has (default or declared) it'll spill an unfriendly stack trace when trying to remove it. |
|
Okay, reverse relationships are not (have never been) included by default, so you don't need to do this, but we should clearly be more graceful in this case. |
Assert fields in `exclude` are model fields
|
Thanks! |
|
I just realized that a long time ago |
I guess something changed in the way DRF 3 includes default many-to-many fields for
ModelSerializer, because as soon as I upgraded I got this unhelpful stack-trace:Before I had to exclude this field specifically, now it's not even there.