-
-
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
upgrading from 3.3.0 to 3.3.1 causes error: FieldDoesNotExist: <Model> has no field named u'id' #3674
Comments
Not directly linked though similar. #3593 was for related field while you have the issue on the main model. |
Here's the smallest possible test case, it works in 3.3.0 and fails in 3.3.1: from django.conf import settings
if not settings.configured:
settings.configure(
MIGRATION_MODULES={'__main__': 'migrations'},
INSTALLED_APPS=('__main__',))
from django.apps import apps
apps.populate(settings.INSTALLED_APPS)
from django.db import models
from rest_framework import serializers
class TestParentModel(models.Model):
title = models.CharField(max_length=64)
class TestChildModel(models.Model):
parent = models.ForeignKey(TestParentModel, related_name='children')
value = models.CharField(primary_key=True, max_length=64)
class TestChildModelSerializer(serializers.ModelSerializer):
class Meta:
model = TestChildModel
fields = ('value',)
class TestParentModelSerializer(serializers.ModelSerializer):
class Meta:
model = TestParentModel
fields = ('id', 'title', 'children')
parent = TestParentModel(title='abc')
child = TestChildModel(value='def', parent=parent)
serializer = TestParentModelSerializer(parent)
print serializer.data |
So, I did a little digging around on this issue using the test case posted above and here's what I found: The issue does appear to be coming from the change made in #3593 in Sorry if that is really confusing. Tracing all those relationships has left me somewhat incoherent. I'll put up a PR with a fix that solves the issue and maybe that will make things a bit clearer, although I'm not convinced it is the best/right fix. |
Thanks for digging into this @benred42! Happy to test your PR in my environment when it's ready. :) |
Noting that #3696 does fix the errors in my environment. Note from @tomchristie this is now #3852 |
@beaugunderson Okay, good to know. If we can replicate in a test case then we're good to go! |
It looks like this has a good PR that includes a good test case now: #3852. :) |
I believe it may be related to #3593.
See here for a model that causes this error when serialized.
I think the issue affects models that have a primary key that's not called
id
. (In this modelvalue
is the primary key).The text was updated successfully, but these errors were encountered: