Re: [Django] #26491: Duplicated queries with nested prefetch

2016-04-12 Thread Django
#26491: Duplicated queries with nested prefetch
-+-
 Reporter:  duduklein|Owner:  nobody
 Type:   |   Status:  closed
  Cleanup/optimization   |
Component:  Database layer   |  Version:  1.9
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  duplicate
 Keywords:   | Triage Stage:
 |  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by timgraham):

 * status:  new => closed
 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * type:  Uncategorized => Cleanup/optimization
 * needs_docs:   => 0
 * resolution:   => duplicate


Comment:

 I tested the code from the description and this seems to be a duplicate of
 #25546 which is fixed in master (which will be Django 1.10).

--
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.6a5c8542a35e536dac05cf045f34d02e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


[Django] #26491: Duplicated queries with nested prefetch

2016-04-11 Thread Django
#26491: Duplicated queries with nested prefetch
--+
 Reporter:  duduklein |  Owner:  nobody
 Type:  Uncategorized | Status:  new
Component:  Database layer (models, ORM)  |Version:  1.9
 Severity:  Normal|   Keywords:
 Triage Stage:  Unreviewed|  Has patch:  0
Easy pickings:  0 |  UI/UX:  0
--+
 This ticket may be related to #26318 , but it's not the same since it does
 not involve repeated models.

 Consider the following 3 test models:
 {{{
 class Test1(models.Model):
 pass

 class Test2(models.Model):
 test1 = models.ForeignKey(Test1, related_name="tests2")

 class Test3(models.Model):
 test2 = models.ForeignKey(Test2, related_name="tests3")
 }}}

 Through the shell, we create initial entries and run the nested prefetch
 queries. We verify that the last 2 queries are duplicated:
 {{{
 from test.models import Test1, Test2, test3
 from django.db import connection
 from django.db.models import Prefetch

 t1 = Test1.objects.create()
 t2 = Test2.objects.create(test1 = t1)
 t3 = Test3.objects.create(test2 = t2)

 connection.queries_log.clear()

 tests2_prefetch = Prefetch("tests2",
 Test2.objects.prefetch_related("tests3"))
 Test1.objects.prefetch_related(tests2_prefetch)

 assert len(connection.queries) == 4
 assert connection.queries[-1] == connection.queries[-2]
 }}}

 We had 4 queries instead of 3 expected and the last 2 are duplicated (to
 prefetch Test3 entries).

--
Ticket URL: 
Django 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.d3b71c38ebab04c1490bda0b6ef4c816%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.