Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Assert fields inexclude are model fields#2319
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
lovelydinosaur commentedDec 18, 2014
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? |
maryokhin commentedDec 18, 2014
classChannel(models.Model):name=models.CharField(max_length=128)classSubscription(models.Model):channel=models.ForeignKey(Channel,related_name='subscribers') classChannelSerializer(ModelSerializer):classMeta():model=Channelexclude= ('subscribers', ) Here I would have something like the following: exclude= ('subscribers',)field_name='subscribers'fields= ['id','name'] Ithink 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. |
lovelydinosaur commentedDec 18, 2014
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
lovelydinosaur commentedDec 18, 2014
Thanks! |
maryokhin commentedDec 19, 2014
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.