-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
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.