Saturday, February 13, 2016

Re: Django is creating duplicate queries for prefetch_related

Thanks Tim, from the ticket and Patch it looks like this was my issue. 

On Sun, 14 Feb 2016 at 08:20 Tim Graham <timograham@gmail.com> wrote:
Maybe https://code.djangoproject.com/ticket/25546 fixes it? This will be in Django 1.10.


On Friday, February 12, 2016 at 10:18:22 PM UTC-5, Dheerendra Rathor wrote:
Hello,

Recently I was monitoring db queries created by Django and a particular block was behaving unusual.
Here is the code block:

        from django.db import connection, reset_queries
        reset_queries()
        group = get_object_or_404(
            Group.objects.select_related('course').prefetch_related(
                Prefetch(
                    'concepts',
                    queryset=Concept.objects.filter(is_published=True).prefetch_related(
                        'videos', 'pages',
                    ),
                ),
            ).only('course', 'playlist'),
            pk=pk,
        )

        s4 = connection.queries
        k4 = len(s4)
        reset_queries()



Now, the interesting part is that prefetch queries are made twice for videos and pages. Hereis the query dump https://paste.kde.org/psrp4orn6

It is making same queries twice with exactly same parameters. 

Can someone please explain it for me? In my view, it should not happen. I'm missing something here? 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a8a7e2f6-999f-4eaa-a045-bcf187c11b94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAByqUghphY4P6-k0%3D9xBMj_vL2vT_SNrjACPtjcvGOENKiWWmg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment