diff options
| author | Rachel Tobin <rmtobin@users.noreply.github.com> | 2017-07-21 15:21:13 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-07-21 18:26:03 -0400 |
| commit | 801b6fb32e36a9b61ae469e29e17650dd8afd9fe (patch) | |
| tree | 0744d5fc5ab2b509450580f14bafca542b1c39e0 | |
| parent | b0304428d682716db8b18e4ba452e2521f462e4a (diff) | |
[1.11.x] Fixed #28418 -- Fixed queryset crash when using a GenericRelation to a proxy model.
Backport of f9e5f9ae9f83c7ddf5e5d3c369b6bf54a9b80ab5 from master
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/contrib/contenttypes/fields.py | 2 | ||||
| -rw-r--r-- | docs/releases/1.11.4.txt | 3 | ||||
| -rw-r--r-- | tests/generic_relations_regress/models.py | 6 | ||||
| -rw-r--r-- | tests/generic_relations_regress/tests.py | 5 |
5 files changed, 16 insertions, 1 deletions
@@ -633,6 +633,7 @@ answer newbie questions, and generally made Django that much better: pradeep.gowda@gmail.com Preston Holmes <preston@ptone.com> Preston Timmons <prestontimmons@gmail.com> + Rachel Tobin <rmtobin@me.com> Rachel Willmer <http://www.willmer.com/kb/> Radek Švarz <http://www.svarz.cz/translate/> Rajesh Dhawan <rajesh.dhawan@gmail.com> diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index a273cf0347..6c4eb43ac1 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -368,7 +368,7 @@ class GenericRelation(ForeignObject): # generating a join to the parent model, then generating joins to the # child models. path = [] - opts = self.remote_field.model._meta + opts = self.remote_field.model._meta.concrete_model._meta parent_opts = opts.get_field(self.object_id_field_name).model._meta target = parent_opts.pk path.append(PathInfo(self.model._meta, parent_opts, (target,), self.remote_field, True, False)) diff --git a/docs/releases/1.11.4.txt b/docs/releases/1.11.4.txt index 180d758246..1f0081c4b6 100644 --- a/docs/releases/1.11.4.txt +++ b/docs/releases/1.11.4.txt @@ -35,3 +35,6 @@ Bugfixes ``checkbox_name``, ``checkbox_id``, ``is_initial``, ``input_text``, ``initial_text``, and ``clear_checkbox_label`` are now attributes of ``widget`` rather than appearing in the top-level context. + +* Fixed queryset crash when using a ``GenericRelation`` to a proxy model + (:ticket:`28418`). diff --git a/tests/generic_relations_regress/models.py b/tests/generic_relations_regress/models.py index eb4f645d34..669e7b7186 100644 --- a/tests/generic_relations_regress/models.py +++ b/tests/generic_relations_regress/models.py @@ -21,10 +21,16 @@ class Link(models.Model): return "Link to %s id=%s" % (self.content_type, self.object_id) +class LinkProxy(Link): + class Meta: + proxy = True + + @python_2_unicode_compatible class Place(models.Model): name = models.CharField(max_length=100) links = GenericRelation(Link) + link_proxy = GenericRelation(LinkProxy) def __str__(self): return "Place: %s" % self.name diff --git a/tests/generic_relations_regress/tests.py b/tests/generic_relations_regress/tests.py index d3986b6916..b2d5b08692 100644 --- a/tests/generic_relations_regress/tests.py +++ b/tests/generic_relations_regress/tests.py @@ -244,3 +244,8 @@ class GenericRelationTests(TestCase): def test_ticket_22982(self): place = Place.objects.create(name='My Place') self.assertIn('GenericRelatedObjectManager', str(place.links)) + + def test_filter_on_related_proxy_model(self): + place = Place.objects.create() + Link.objects.create(content_object=place) + self.assertEqual(Place.objects.get(link_proxy__object_id=place.id), place) |
