#36135: Prefetching a GenericRelation raises AttributeError
--------------------------------------+------------------------------------
     Reporter:  john                  |                    Owner:  (none)
         Type:  Bug                   |                   Status:  new
    Component:  contrib.contenttypes  |                  Version:  5.1
     Severity:  Normal                |               Resolution:
     Keywords:  prefetch              |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):

 * component:  Uncategorized => contrib.contenttypes
 * stage:  Unreviewed => Accepted
 * summary:  Prefetch GenericForeignKey with ManyToMany field error =>
     Prefetching a GenericRelation raises AttributeError

Comment:

 Thank you for the report!

 Replicated with Simon's test case in the forum, which raises:
 `AttributeError: 'Bookmark' object has no attribute 'favorite_fkey'. Did
 you mean: 'favorite_tags'?`

 {{{#!diff
 diff --git a/tests/prefetch_related/tests.py
 b/tests/prefetch_related/tests.py
 index c153c0d9ec..3a2f5b4c05 100644
 --- a/tests/prefetch_related/tests.py
 +++ b/tests/prefetch_related/tests.py
 @@ -1243,6 +1243,12 @@ def test_deleted_GFK(self):
                  ],
              )

 +    def test_reverse_gfk(self):
 +        bookmark = Bookmark.objects.create()
 +        TaggedItem.objects.create(content_object=bookmark,
 favorite=bookmark)
 +        with self.assertNumQueries(1):
 +
 list(TaggedItem.objects.prefetch_related("favorite_bookmarks"))
 +
  class MultiTableInheritanceTest(TestCase):
      @classmethod
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36135#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019497d127ca-3ed3553b-3500-4816-9351-1415f7501914-000000%40eu-central-1.amazonses.com.

Reply via email to