﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31130	GenericRelation error if not use default field name for GenericForeignKey	inkawarrior	nobody	"If change the name of either content_type or object_id field from the example [https://docs.djangoproject.com/en/3.0/ref/contrib/contenttypes/#generic-relations]
{{{
class TaggedItem(models.Model):
    tag = models.SlugField()
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    bookmark_id = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'bookmark_id')

    def __str__(self):
        return self.tag

class Bookmark(models.Model):
    url = models.URLField()
    tags = GenericRelation(TaggedItem)

}}}
And run the code from the example

{{{
>>> b = Bookmark(url='https://www.djangoproject.com/')
>>> b.save()
>>> t1 = TaggedItem(content_object=b, tag='django')
>>> t1.save()
>>> t2 = TaggedItem(content_object=b, tag='python')
>>> t2.save()
>>> b.tags.all()
}}}

Will get the following error


{{{
  File ""C:\Users\User\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\contenttypes\fields.py"", line 560, in get_queryset
    return self.instance._prefetched_objects_cache[self.prefetch_cache_name]
AttributeError: 'Bookmark' object has no attribute '_prefetched_objects_cache'
}}}

----

{{{
django.core.exceptions.FieldError: Cannot resolve keyword 'object_id' into field. Choices are: bookmark_id, content_object, content_type, content_type_id, id, tag
}}}

The is no problem when using the default name"	Bug	closed	Core (Cache system)	3.0	Normal	invalid			Unreviewed	0	0	0	0	0	0
