Bug with prefetch_related
See original GitHub issuePosted this few weeks ago to the mailinglist, but seems that it’s dead so re-posting here. (Maybe it would be a good idea to retire the mailinglist or post a notification there that it’s not been actively followed?)
So, I have a following model with tags:
tags = TaggableManager(through='knuckles.UUIDTaggedItem', blank=True)
where UUIDTaggedItem is:
class UUIDTaggedItem(GenericUUIDTaggedItemBase, TaggedItemBase):
class Meta:
verbose_name = "Tag"
verbose_name_plural = "Tags"
When I query for the tags I get following:
In [18]: e = LiveEvent.objects.get(slug='dj-tony-004')
In [19]: e.tags.all()
Out[19]: <QuerySet [<Tag: 90s>, <Tag: dj tony>, <Tag: house>, <Tag: radioshow>, <Tag: 00's>, <Tag: trance>, <Tag: 90's>, <Tag: eurodance>]>
In [20]: e = LiveEvent.objects.prefetch_related('tags').get(slug='dj-tony-004')
In [21]: e.tags.all()
Out[21]: <QuerySet []>
So when using prefetch_related, I always get empty tags. Not sure if I’m doing something wrong here or if this is a bug?
I’m using Django version 1.11 and django-taggit version 0.22.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Strange prefetch_related Issue. Is this a bug? - Google Groups
It appears that the issue is because if the first item in the list is of a type "sms", then prefetch_related looks up...
Read more >Prefetch_related failing against SQL Server - Stack Overflow
This bug occurs regularly for me under many different circumstances in this particular setup (always same Django version, driver, and DB), it's ...
Read more >19607 (prefetch_related crash) - Django's bug tracker
The issue is hard to reproduce, but it seems to occur more when queryset has nested relations with more than one related object...
Read more >GraphQL should use select_related and prefetch_related to ...
There is a bug in graphene_django that eliminates any usage of select_related or prefetch_related. This works around that limitation and allows the user...
Read more >Five Common Django Mistakes - LAAC Technology
However, if we add a prefetch_related to the organization query, ... we've created a bug here where the system attempts to fetch the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks a lot for the patch and the tests, @fumuumuf ! 👍
This occurs because
instance_attr
value isn’t match_prefetch_related_val
. It worked fine by modifying as below. (only MySQL, SQLite3)https://github.com/jazzband/django-taggit/blob/954d8360102fb2102db246bde1336a7e58ff10f2/taggit/managers.py#L114