Re: [Django] #10060: Multiple table annotation failure

2023-07-28 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Natalia Bidart):

 #34728 is a (fairly) duplicate of this one.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701899cfaeab5-006a4c71-ed96-4021-8d72-7f995b94128a-00%40eu-central-1.amazonses.com.


Re: [Django] #10060: Multiple table annotation failure

2022-12-01 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by David Kwong):

 * cc: David Kwong (added)


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070184d0d163f6-f8713164-f078-410d-ab19-c9c1e4a2bf23-00%40eu-central-1.amazonses.com.


Re: [Django] #10060: Multiple table annotation failure

2021-10-18 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Matthijs Kooijman):

 For anyone else running into this, a reasonable workaround seems to be to
 use subqueries for aggregating annotations. This is a bit verbose/hacky in
 Django currently, as shown by the multitude of approaches in the
 stackoverflow link from [[comment:69|Antoine's comment]]. However, I've
 successfully used the [[https://github.com/martsberger/django-sql-utils
 |django-sql-utils]] package for this just now. That sounds a bit bulky,
 but it just has two utilities, one of which is a `SubqueryAggregate` class
 (with derived `SubqueryCount`, `SubquerySum`, etc.) that make converting a
 regular joining aggregate into a subquery aggregate easy and concise,
 without changing the structure much.

 For example taking the example from [[comment:66|comment 66]] and
 converting the second annotation to a subquery with django-sql-utils,
 you'd get:

 {{{
 Branch.objects.annotate(
 total=Sum('center__client__loan__amount'),
 
repaid=SubquerySum('center__client__loan__payment_schedule__payments__principal'),
 )
 }}}

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/081.f2bd649eb8b03b75ac8a135cbef0b98f%40djangoproject.com.


Re: [Django] #10060: Multiple table annotation failure

2021-06-10 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  dev
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Adam Sołtysik):

 It's very surprising that aggregations aren't done in subqueries. The
 problem arises even with basic, one-field aggregations, when there are
 duplicates in the original query. So something like this, with a single
 reverse foreign key relation:

 {{{
 
User.objects.filter(orders__date=today).distinct().values('first_name').annotate(Count('pk'))
 }}}

 may produce wrong results (will count orders instead of users), even
 though it looks safe with `.distinct()`. From what I've found, the
 documentation doesn't warn about such cases.

 Funnily enough, when I have rewritten one of my not working queries with
 sum aggregation to use a subquery, it actually became faster (on a table
 with ~100k rows), but of course YMMV.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/081.47c34554437d931983ab20eb43f33b18%40djangoproject.com.


Re: [Django] #10060: Multiple table annotation failure

2019-06-17 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Antoine):

 People affected by this issue may find this useful:

 https://stackoverflow.com/questions/56567841/django-count-and-sum-
 annotations-interfere-with-each-other

-- 
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/081.0715f21a2d50e6dc79356cd6d04d8488%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2019-06-16 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Antoine):

 * cc: Antoine (added)


-- 
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/081.539987ddb57366ccc3298c551642b025%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2019-03-22 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by wilhelmhb):

 Replying to [comment:57 powderflask]:
 A huge thanks to powderflask: for the ones knowledgeable enough with SQL,
 this is the way to go =)

 I also tried the solution described here:
 [https://stackoverflow.com/questions/48598245/multiple-annotate-with-sum-
 and-display-data-in-admin-django/48607830#48607830], alas without
 success...

 > Replying to [comment:9 bendavis78]:
 > In [comment:16 comment16] bendavis78 recommends this query to solve the
 issue:
 > >  {{{
 > > #!sql
 > > SELECT
 > >   u.email,
 > >   (SELECT SUM(points) FROM point_earning WHERE user_id=u.id) AS
 points_earned,
 > >   (SELECT SUM(points) FROM point_expense WHERE user_id=u.id) AS
 points_spent
 > > FROM
 > >   "user" u
 > > }}}
 >
 > For others who might arrive here looking for a reasonable way to work
 around this issue, the following worked well for me.  I added a custom
 Queryset method to the Manager class, and used a
 [https://docs.djangoproject.com/en/1.9/ref/models/expressions/#raw-sql-
 expressions RawSQL()] expression to create the annotations.   This at
 least encapsulates the SQL code and allows the annotation to be integrated
 with a normal django queryset.  Here's a sample for the example given
 above:
 >
 > {{{
 > #!python
 > def annotate_sum_for_user(user_related_modelClass, field_name,
 annotation_name):
 > raw_query = """
 >   SELECT SUM({field}) FROM {model} AS model
 >   WHERE model.user_id = user.id
 > """.format(
 > field = field_name,
 > model = user_related_modelClass._meta.db_table,
 > )
 >
 > annotation = {annotation_name: RawSQL(raw_query, [])}
 > return self.annotate(**annotation)
 > }}}
 >
 > Usage for above query on presumed User model:
 > {{{
 > #!python
 > users = models.User.objects\
 > .annotate_sum_for_user(PointEarning, 'points', 'points_earned')\
 > .annotate_sum_for_user(PointExpense, 'points', 'points_spent')
 > }}}
 >
 > Hope someone finds this useful, and a word of HUGE thanks to those who
 worked to get a statement of this issue and a link to this thread into the
 django documentation -- probably saved me hours.

-- 
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/081.31cb48de32bc71efde0aef2de3b10441%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2018-12-05 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Simon Charette):

 Since this ticket has more exposure I wanted to mention that #28296 ought
 to fix this by allowing a `subquery` argument to be passed to aggregate
 functions.

 If it was to be implemented the original report queryset could be made to
 return the correct results easily

 {{{#!python
 Branch.objects.annotate(
 total=Sum('center__client__loan__amount'),
 repaid=Sum('center__client__loan__payment_schedule__payments__principal',
 subquery=True),
 )
 }}}

 Once this lands the ORM should be in a position to detect and warn about
 or even deprecate multiple cross joined annotations.

 Given the current existing logic with the `Subquery` expression it
 shouldn't be too hard for someone with basic expression knowledge about
 the ORM to implement a patch if anyone is interested in contributing.

-- 
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/081.c1cbc64fdb4175b04978a4ba23b2a4e2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2018-05-24 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Adam M. Costello):

 * cc: Adam M. Costello (added)


Comment:

 Does anyone here understand roughly what is safe to do with annotate()?

 If I call annotate() only once on a queryset, with only one argument, is
 that always safe, no matter how many relationships I follow in annotate()
 and filter()?

 Is it safe to pass multiple arguments to annotate() (or call annotate()
 multiple times) if none of the annotations follow any relationships? Even
 if there are relationships followed inside filter()?

 Do the problems with annotate() also apply to aggregate(), or is it safe
 to pass multiple arguments to aggregate() ? Is it safe to call annotate()
 with one argument and then call aggregate()?

-- 
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/081.9308bc2e5441bf5fc2241307f8b14f03%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2018-02-04 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Israel Saeta Pérez):

 FTR: See a workaround using `SubQuery` for the issue with annotate
 described in this ticket, in this SO post:
 https://stackoverflow.com/questions/48598245/multiple-annotate-with-sum-
 and-display-data-in-admin-django

-- 
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/081.4234cb66da8e31a853f1db5b5d7d3a6b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2018-01-21 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by th0th):

 * cc: th0th (added)


-- 
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/081.9923866b6af85cc06b092af0560df92a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2017-09-28 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Maxim):

 * cc: Maxim (added)


Comment:

 I think a note about this "feature" in the docs would be helpful.

-- 
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/081.fa6431ba11979addd35219c3d021a8c7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2017-07-04 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Artem.Bernatskyy):

 Just have spent 5 hours debugging this bug.

 +1

-- 
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/081.dc90afd3ca58bb0226d5aae443ab363c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2016-11-16 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:  (none)
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by akermen):

 No sure this will work for all different cases, at least it worked well
 for me and the below simplified test case:

 Model definitions of test case,
 {{{
 class ModelA(models.Model):
 title = models.CharField(max_length=255, blank=False, null=False,
 unique=True)

 class ModelB(models.Model):
 parent = models.ForeignKey(ModelA, on_delete=models.CASCADE)
 value = models.IntegerField()

 class ModelC(models.Model):
 parent = models.ForeignKey(ModelA, on_delete=models.CASCADE)
 }}}

 and sample data:
 {{{
 instance_a_1 = ModelA(title="instance1")
 instance_a_1.save()
 instance_b = ModelB(parent=instance_a_1, value=1)
 instance_b.save()
 instance_b = ModelB(parent=instance_a_1, value=3)
 instance_b.save()
 instance_b = ModelB(parent=instance_a_1, value=5)
 instance_b.save()
 instance_c = ModelC(parent=instance_a_1)
 instance_c.save()
 instance_c = ModelC(parent=instance_a_1)
 instance_c.save()
 instance_c = ModelC(parent=instance_a_1)
 instance_c.save()
 instance_c = ModelC(parent=instance_a_1)
 instance_c.save()
 instance_c = ModelC(parent=instance_a_1)
 instance_c.save()

 instance_a_2 = ModelA(title="instance2")
 instance_a_2.save()
 instance_b = ModelB(parent=instance_a_2, value=7)
 instance_b.save()
 instance_b = ModelB(parent=instance_a_2, value=11)
 instance_b.save()
 instance_c = ModelC(parent=instance_a_2)
 instance_c.save()
 instance_c = ModelC(parent=instance_a_2)
 instance_c.save()
 instance_c = ModelC(parent=instance_a_2)
 instance_c.save()
 }}}

 Trying to get two independent annotations from two different tables (sum
 of values from ModelB and number of ModelC instances per ModelA instance):
 {{{
 for a in ModelA.objects.all() \
 .annotate(sumB=Sum('modelb__value')) \
 .annotate(countC=Count('modelc', distinct=True)):
 print "%s:  sumB: %s  countC: %s" % (a.title, a.sumB, a.countC)
 }}}

 we get these results
 {{{
 instance1:  sumB: 45  countC: 5
 instance2:  sumB: 54  countC: 3
 }}}

 instead of these:
 {{{
 instance1  sumB: 9   countC: 5
 instance2  sumB: 18   countC: 3
 }}}
 no surprise until here.

 As you can see the 'sumB' values are repeated (multiplied) by a factor,
 lets account that factor inside single query:
 {{{
 for a in ModelA.objects.all() \
 .annotate(countC=Count('modelc', distinct=True)) \
 .annotate(countB=Count('modelb')) \
 .annotate(countB_distinct=Count('modelb', distinct=True)) \
 .annotate(sumB_multiplied=Sum('modelb__value')) \
 .annotate(sumB=(F('sumB_multiplied') * F('countB_distinct')) /
 F('countB')):
 print "%s  sumB: %s   countC: %s" % (a.title, a.sumB, a.countC)
 }}}

 and get correct values:
 {{{
 instance1  sumB: 9   countC: 5
 instance2  sumB: 18   countC: 3
 }}}

--
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/081.ce586e4a14d263f3156119323db6e639%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2016-08-27 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by daniloakamine):

 The solution proposed by '''powderflask''' is very interesting and worked
 well.
 This ticket helped me a lot to understand the big problem.

 Thank you all, guys.

--
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/081.8cf48034893fd79026e73206c13217dd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2016-07-17 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by SonOfLilit):

 I just ran into this and submitted a duplicate bug (#26898).

 I see a lot of sadness in this thread, joining my own.

 My offer to fix if someone knowledgeable about the code can mentor me
 still stands. I assume at least detecting it and generating a warning
 shouldn't be too hard?

--
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/081.0c7a15e2f289aac06703704bf7df0f4a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2016-05-06 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by powderflask):

 Replying to [comment:9 bendavis78]:
 In [comment:16 comment16] bendavis78 recommends this query to solve the
 issue:
 >  {{{
 > #!sql
 > SELECT
 >   u.email,
 >   (SELECT SUM(points) FROM point_earning WHERE user_id=u.id) AS
 points_earned,
 >   (SELECT SUM(points) FROM point_expense WHERE user_id=u.id) AS
 points_spent
 > FROM
 >   "user" u
 > }}}

 For others who might arrive here looking for a reasonable way to work
 around this issue, the following worked well for me.  I added a custom
 Queryset method to the Manager class, and used a
 [https://docs.djangoproject.com/en/1.9/ref/models/expressions/#raw-sql-
 expressions RawSQL()] expression to create the annotations.   This at
 least encapsulates the SQL code and allows the annotation to be integrated
 with a normal django queryset.  Here's a sample for the example given
 above:

 {{{
 #!python
 def annotate_sum_for_user(user_related_modelClass, field_name,
 annotation_name):
 raw_query = """
   SELECT SUM({field}) FROM {model} AS model
   WHERE model.user_id = user.id
 """.format(
 field = field_name,
 model = user_related_modelClass._meta.db_table,
 )

 annotation = {annotation_name: RawSQL(raw_query, [])}
 return self.annotate(**annotation)
 }}}

 Usage for above query on presumed User model:
 {{{
 #!python
 users = models.User.objects\
 .annotate_sum_for_user(PointEarning, 'points', 'points_earned')\
 .annotate_sum_for_user(PointExpense, 'points', 'points_spent')
 }}}

 Hope someone finds this useful, and a word of HUGE thanks to those who
 worked to get a statement of this issue and a link to this thread into the
 django documentation -- probably saved me hours.

--
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/081.fdaf7a380c0bf5becc80ad0748b280fc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2016-03-07 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by tomaszn):

 * cc: nowak2000@… (added)


--
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/081.941f802815764211aaf73cc355533bf4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2015-12-15 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Tim Graham ):

 In [changeset:"ea63cf8d424780aed35e9973bf5e4dbb652c7d8a" ea63cf8d]:
 {{{
 #!CommitTicketReference repository=""
 revision="ea63cf8d424780aed35e9973bf5e4dbb652c7d8a"
 [1.9.x] Refs #10060 -- Corrected description of multiple annotations bug.

 Backport of 3d2236773ba88e330841b8c72183b0e978e10909 from master
 }}}

--
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/081.972eac0f4a218c535de86206757d9f61%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2015-12-15 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Tim Graham ):

 In [changeset:"3d2236773ba88e330841b8c72183b0e978e10909" 3d22367]:
 {{{
 #!CommitTicketReference repository=""
 revision="3d2236773ba88e330841b8c72183b0e978e10909"
 Refs #10060 -- Corrected description of multiple annotations bug.
 }}}

--
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/081.a7278dd7a291f4a9e006e6ff739c4082%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2015-12-08 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by timgraham):

 If I understood Anssi correctly, the existing documentation warning
 [https://groups.google.com/d/msg/django-
 developers/qiYKd1YZY_E/Tgn0p1wHCQAJ isn't correct], so I submitted
 [https://github.com/django/django/pull/5795 a revision].

--
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/081.92d4040028ff01c54838069bcccbae14%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2015-07-13 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by glic3rinu):

 * cc: glic3rinu (added)


--
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/081.11662f9e47f93e7ac0fb0e1a299980fb%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2015-03-25 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by camillobruni):

 Replying to [comment:50 camillobruni]:
 > I recently ran into a similar problem. The deep joining causes an
 explosion of values possibly resulting in many duplicate values. I fixed
 this in https://github.com/django/django/pull/4388 by implementing the
 DISTINCT parameter on the Aggregate functions. Hence you can do
 > {{{Sum('center__client__loan__payment_schedule__payments__principal',
 distinct=True)}}}
 > which ignores the duplicate entries.
 >
 > It might be that the issue at hand is slightly different, but this
 solves at least one particular case.

 Sorry for the noise, I was wrong (in hindsight: "obviously")
 http://www.sqlteam.com/article/how-to-use-group-by-with-distinct-
 aggregates-and-derived-tables describes the problem I thought of dealing
 with in more detail.

--
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/081.7c507542032e94f8c6b300e70dc07e49%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2015-03-23 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by camillobruni):

 I recently ran into a similar problem. The deep joining causes an
 explosion of values possibly resulting in many duplicate values. I fixed
 this in https://github.com/django/django/pull/4388 by implementing the
 DISTINCT parameter on the Aggregate functions. Hence you can do
 {{{Sum('center__client__loan__payment_schedule__payments__principal',
 distinct=True)}}}
 which ignores the duplicate entries.

 It might be that the issue at hand is slightly different, but this solves
 at least one particular case.

--
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/081.8f748e31a9d8935da37b5263c8a2754b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2014-12-03 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:  Accepted
 Keywords:   |  Needs documentation:  0
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-

Comment (by Tim Graham ):

 In [changeset:"a87ade7e30c80de93ec7ad8335d8714b494a58fb"]:
 {{{
 #!CommitTicketReference repository=""
 revision="a87ade7e30c80de93ec7ad8335d8714b494a58fb"
 [1.6.x] Documented a current limitation of multiple table annotation; refs
 #10060.

 Backport of 4b23a6c7a9232cc07ec95fe98be17efbd4449822 from master
 }}}

--
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/081.61ae97d5384ba601fbe9f32f77d66840%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2014-12-03 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:  Accepted
 Keywords:   |  Needs documentation:  0
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-

Comment (by Tim Graham ):

 In [changeset:"48bd44670b4c58735d5cdf6762d6b61219ecbb12"]:
 {{{
 #!CommitTicketReference repository=""
 revision="48bd44670b4c58735d5cdf6762d6b61219ecbb12"
 [1.7.x] Documented a current limitation of multiple table annotation; refs
 #10060.

 Backport of 4b23a6c7a9232cc07ec95fe98be17efbd4449822 from master
 }}}

--
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/081.7532e59e0ec72a24969261582fd2cae3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2014-12-03 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:  Accepted
 Keywords:   |  Needs documentation:  0
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-

Comment (by Tim Graham ):

 In [changeset:"4b23a6c7a9232cc07ec95fe98be17efbd4449822"]:
 {{{
 #!CommitTicketReference repository=""
 revision="4b23a6c7a9232cc07ec95fe98be17efbd4449822"
 Documented a current limitation of multiple table annotation; refs #10060.
 }}}

--
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/081.03f631a6ad050f30fb89470de7c7763d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2014-11-30 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:  Accepted
 Keywords:   |  Needs documentation:  0
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-

Comment (by benjaoming):

 Agreed with anonymous 01/28/2013 that there needs to be at least some
 documentation on this: https://github.com/django/django/pull/3654

--
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/081.eb517f8f3b531a82c34089104a97b87d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2014-06-14 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:  Accepted
 Keywords:   |  Needs documentation:  0
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-

Comment (by timo):

 Bumping this ticket accomplishes nothing. If you want to see it addressed,
 please write a patch.

-- 
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/081.d99a84797135615b05a11575fc42e3a6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2014-06-14 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:  Accepted
 Keywords:   |  Needs documentation:  0
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-

Comment (by anonymous):

 bump

-- 
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/081.3e2268ed42cbb5bda052e4fc670a9129%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Django] #10060: Multiple table annotation failure

2013-08-14 Thread Django
#10060: Multiple table annotation failure
-+-
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  Database layer   |  Version:  master
  (models, ORM)  |   Resolution:
 Severity:  Normal   | Triage Stage:  Accepted
 Keywords:   |  Needs documentation:  0
Has patch:  0|  Patch needs improvement:  0
  Needs tests:  0|UI/UX:  0
Easy pickings:  0|
-+-

Comment (by anonymous):

 Bump

-- 
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/081.44eb0b854b356e1acda5e4d0aa225e58%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Django] #10060: Multiple table annotation failure

2013-01-28 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  master
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+

Comment (by anonymous):

 At this point the documentation on annotations can be considered to be
 intentionally misleading.

 It is hard not to think this given the severity of the issue and the
 comments above.

 Yes a code fix is hard but at least an obviously tentative documentation
 "fix" can be pushed fairly easily.

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Django] #10060: Multiple table annotation failure

2012-11-27 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  master
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+

Comment (by akaariai):

 This is somewhat hard problem. We could do automatic subquery pushdown for
 aggregates - it isn't exactly easy but most of the pieces are already
 there. I am not sure how well such queries will perform. Although that
 isn't perhaps too important. If the results aren't correct speed doesn't
 matter...

 I think a good start to this would be documentation + detecting the
 problematic situations and throwing an error in those cases. Basically if
 we have two multijoins in the query (from filtering, aggregation or
 something else) and aggregation is used then the query is likely wrong.
 However this condition is a little too restrictive - something like:
 {{{
 qs.filter(translations__lang='fi', translations__name='foo')
 }}}
 introduces a multijoin to translations, yet the query is safe as
 translations.lang is unique. Detecting if we have a unique multijoin is
 going to be nasty. So, we need a way to bypass this error checking.

 Proposal: aggregates get a new kwarg "inline" - default False. If inline
 is False, then multiple multijoins in single query will raise an error. If
 it is True, the aggregate is forced to be joined to the query (that is, to
 do what aggregates do today). Later on we will likely add another kwarg
 "subquery" - defaults again to False. If set to True the aggregate is
 forced to subquery (something like in comment:9). We could also add kwarg
 "subselect". Later on maybe also "lateral_subquery" and so on.

 The proposal allows us to throw an error, yet give users the ability to
 force the ORM to generate the queries they are using now. It also allows
 for extending the same API if we get subquery aggregate support some day.

 I think we need to add the information about multijoins to JoinInfo, and
 add the info about used joins to aggregates when they are added to the
 query. Then at compiler stage, check for all inline=False aggregates if
 there are multijoins in the query not used by the aggregate itself. If so,
 throw an error. Changes should be needed at query.setup_joins(),
 compiler.get_from_clause() and then a way to annotate the used joins into
 the aggregate (this should not be too hard).

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Django] #10060: Multiple table annotation failure

2012-11-25 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  master
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+
Changes (by michaelB):

 * cc: michaelB (added)


-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Django] #10060: Multiple table annotation failure

2012-11-25 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  master
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+

Comment (by michael@…):

 Hmm, another victim here. Spent 2 hours trying to understand why my
 numbers were so odd to finally find this bug. This is the first time in
 several django projects I am really feeling left alone :-(
 I am no database expert (which is one reason i LOVE django and it's
 awesome Queryset) so I don't see any way that I could provide
 implementation help or anything, but seeing that this bug is now open for
 several years really makes me shake my head. Even if there is no obvious
 fix available, PLEASE at least update the documentatin to point out this
 issue!

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Django] #10060: Multiple table annotation failure

2012-11-16 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  master
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+

Comment (by aaugustin):

 #19290 is a duplicate.

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Django] #10060: Multiple table annotation failure

2012-01-17 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  SVN
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+
Changes (by Fak3):

 * cc: Fak3 (added)


-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2012-01-03 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  SVN
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+

Comment (by anonymous coward):

 It would seem that argumentum ad infinitum is a common theme on here, no?
 "A is B", "No, A is A and B is B", "Fine, but C is D..." and so on.

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2011-12-08 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  SVN
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+

Comment (by anonymous):

 Really, it seems there are plenty of ticket with patches (complete with
 tests), and with offers to do the work, but the core team doesn't care.

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2011-11-29 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  SVN
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+

Comment (by lukeplant):

 Replying to [comment:31 anonymous]:
 > Is this something that will ever be fixed?

 It will only ever get fixed if someone cares enough to write a patch
 (complete with tests). I think at this point a patch which threw an
 exception for the failure case would be accepted. Obviously ideally this
 would be replaced with a proper fix at some point.

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2011-11-29 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  SVN
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+

Comment (by anonymous):

 Is this something that will ever be fixed?

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2011-10-11 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  SVN
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+

Comment (by anonymous):

 Whoa, thought I was doing something wrong in my code until I searched and
 found this. Isn't this kind of a big deal? As in, with this bug, isn't
 Django's aggregation basically worthless for anyone who's not doing it on
 a single table, or did I miss something?

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2011-10-02 Thread Django
#10060: Multiple table annotation failure
-+
 Reporter:  svsharma@…   |Owner:
 Type:  Bug  |   Status:  new
Component:  ORM aggregation  |  Version:  SVN
 Severity:  Normal   |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+
Changes (by anonymous):

 * ui_ux:   => 0
 * easy:   => 0


Comment:

 Another victim. I have a model {{{Foo}}}. I also have models {{{Bar}}} and
 {{{Baz}}}, which each have a foreign key pointing to {{{Foo}}} with
 related_names {{{'bars'}}}, and {{{'bazs'}}}, respectively:

 {{{

 for foo in Foo.objects.all().annotate(bar_count=Count('bars'),
 baz_count=Count('bazs')):
 print foo.bar_count  # Was correct
 print foo.baz_count  # Was completely wrong, but not by any apparent
 pattern (ie, the numbers seemed to be almost random)

 }}}

 I'm unable to display the {{{baz_count}}} in my template now, unless I
 want to introduce an N+1 problem (ie, {{{foo.bazs.count()}}} during each
 iteration)

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2011-04-01 Thread Django
#10060: Multiple table annotation failure
--+---
   Reporter:  svsharma@…  |Owner:
   Type:  Bug |   Status:  new
  Milestone:  |Component:  ORM aggregation
Version:  SVN | Severity:  Normal
 Resolution:  | Keywords:
   Triage Stage:  Accepted|Has patch:  0
Needs documentation:  0   |  Needs tests:  0
Patch needs improvement:  0   |
--+---
Changes (by SmileyChris):

 * type:   => Bug
 * severity:   => Normal


-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2011-01-14 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by thamedave):

 Another victim.

 This bug means that you can't use annotations at all unless you know
 exactly what is going to happen to your QuerySet later.  Functions cannot
 expect that any QuerySet passed as a parameter is capable of being
 annotated as it may already have been done.

 I am a reasonably to Django, but it seems odd to me that this has remained
 a known bug for 2 years without anyone working on it, or a the
 documentation being changed to reflect the lack of functionality.  I
 understand russell's logic that bugs should not be documented, but if this
 cannot be fixed, then surely it should be removed from intended behaviour.

-- 
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2010-12-29 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by teemu):

 * cc: teemu.kur...@iki.fi (added)

Comment:

 Another victim here. Just spent several hours with finding this bug, which
 had existed several days. This definitely should be either fixed or
 prevented: values that the incorrect query provides are often somewhat in
 the sensible range, depending on your row structures, which can make this
 bug hard to spot.

 I also tested both queries that bendavis78 outlined above and they give
 correct results. Didn't do extensive performance testing yet, with 20K
 rows in the largest table, both queries were between 0.05 and 0.10 secs.

-- 
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 post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2010-07-25 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by mp):

 * cc: mpj...@terreon.de (added)

-- 
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 post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2010-04-29 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by anonymous):

 * cc: g...@codelounge.org (added)

-- 
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 post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2010-04-21 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by fas):

 I also just ran into this bug and it almost went unnoticed. An exception
 would indeed be very nice indicating that this does not work yet.

-- 
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 post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2010-04-20 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by seble...@gmail.com):

 * cc: seble...@gmail.com (added)

-- 
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 post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2010-04-05 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by gabrielhurley):

 * cc: gabrielhurley (added)

Comment:

 chalk up another victim... ::sigh::

-- 
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 post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2010-02-18 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by dablak):

 * cc: dan...@fargas.com (added)

Comment:

 A big bug needs a big shoe...

-- 
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 post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2010-01-26 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by anonymous):

 * cc: cmu...@gmail.com (added)

-- 
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 post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #10060: Multiple table annotation failure

2009-10-16 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by fitoria):

 I can confirm this one... It happens with aggregate too wrong values in 2
 - 5% range.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-08-19 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by anonymous):

 +1 victim

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-07-17 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by bendavis78):

 Regarding the example sql queries in comment 9
 [http://code.djangoproject.com/ticket/10060#comment:9 above],  I've
 discovered that the first query is actually faster.  My database has grown
 fairly large in the past few months, so I've been able to test with more
 clear results (this is using MySQL, by the way).

 Using the JOIN method (where the aggregates are done in a derived join),
 the query was extremely slow.  It took over 30 minutes to execute with
 57,000 rows in the users table.   When I changed the query to the SELECT
 method (where the aggregates are done in a subquery in the select clause),
 the query took only 2 seconds with the exact same results.  I spent a
 whole day on this, and couldn't find a solid explanation for why the
 derived join method was taking so long.  I'd say at this point if anyone
 moves forward with fixing this bug we should put the aggregate in the
 subquery of the select clause.

 I've looked around for an official stance on how to write a query with
 multiple aggregations across different joined tables,  and haven't come up
 with a solid answer.  If anyone does find "the right way" to do it, I'd be
 interested to know -- I think that definitely needs to be settled before
 this bug can be fixed.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-07-16 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by bendavis78):

 I also agree that this should be documented, but perhaps an exception
 should be raise when attempting to do multiple annotations on different
 tables/joins?  I can't think of a situation where that would ever
 guarantee accurate results.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-07-04 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by russellm):

 The milestone was deleted because this is a fairly big problem, without an
 obvious (or particularly easy) solution. There is no potential for data
 loss, and there is a viable workaround - either "don't do it",or use two
 queries rather than one. One of the side effects of a time-based release
 schedule is that some bugs will always exist in releases - unfortunately,
 this is one of those bugs.

 Regarding adding this to a "known bugs" section - we don't document bugs.
 We document intended behavior. The ticket tracker is for bugs.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-07-04 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by seocam):

 Would be nice to know why the milestone was deleted.
 If we are pushing this to 1.2 we need to add it in "Known Bugs" in the doc
 page:
 http://docs.djangoproject.com/en/dev/topics/db/aggregation/

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-05-06 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone: 
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by russellm):

  * milestone:  1.1 =>

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-04-08 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone:  1.1
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by bendavis78):

 Ok, after spending several hours looking through
 django/db/models/sql/query.py,   I feel like my brain has turned to mush.
 This is definitely better left up to the ppl that wrote it.   I hope that
 at some point someone who is capable can write a patch for it.

 I'm against simply adding a "don't do this" in the documentation,  because
 users would simply expect something like this to work -- it's hard to
 understand at a high level why simply adding another annotation from a
 different relation would skew the results.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-04-07 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone:  1.1
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by bendavis78):

 From what I've researched,  joining on subqueries would be faster than
 subqueries in the SELECT clause.  So instead of this:
 {{{
 #!sql
 SELECT
   u.email,
   (SELECT SUM(points) FROM point_earning WHERE user_id=u.id) AS
 points_earned,
   (SELECT SUM(points) FROM point_expense WHERE user_id=u.id) AS
 points_spent
 FROM
   "user" u
 }}}

 ...we would want this:
 {{{
 #!sql
 SELECT
   u.email,
   a.points AS points_earned,
   b.points AS points_spent
 FROM
   "user" u
   LEFT OUTER JOIN (SELECT user_id, SUM(points) AS points FROM
 point_earning GROUP BY user_id) a ON a.user_id=u.id
   LEFT OUTER JOIN (SELECT user_id, SUM(points) AS points FROM
 point_expense GROUP BY user_id) b ON b.user_id=u.id
 ORDER BY u.id
 }}}

 What this does, essentially, is move the aggregate function into a derived
 table which we join onto the main table.  I would imagine a solution to
 this bug would detect if annotations are being used across multiple
 relations, and if so, would adjust the join and select clauses as
 necessary.  I may attempt to write a patch for this soon,  but it seems
 like it would be tough, so there's no guarantees :-p

 Thoughts?

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-04-07 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone:  1.1
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by anonymous):

 * cc: bendavi...@gmail.com (added)

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-04-06 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone:  1.1
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Comment (by bendavis78):

 If anyone were to fix this,  the first question to ask would be how you
 would structure the SQL.  I'm not an SQL efficiency expert,  but I know
 one way to get the correct result would be to use subqueries in the SELECT
 clause:

 For example,  let's say I have a User,  !PointEarning w/
 !ForeignKey(User), and !PointExpense w/ F!oreignKey(User).Let's say I
 want a query to get the user's email, total points earned, and total
 points spent.:

 {{{
 SELECT auth_user.id, auth_user.email, (SELECT SUM(points) FROM
 app_pointearning WHERE user_id=auth_user.id) AS points_earned,  (SELECT
 SUM(points) FROM app_pointexpense WHERE user_id=auth_user.id) AS
 points_spent FROM auth_user
 }}}

 Another way, I believe, is to join on derived tables (sub-queries).
 Whatever way we decide to write the SQL,  django could perhaps detect when
 we're using aggregates accross multiple joins, and alter the structure of
 the query accordingly.   Seems like it could be kinda messy, but at least
 the results would be more what the user expected.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-02-27 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner: 
Status:  new  | Milestone:  1.1
 Component:  ORM aggregation  |   Version:  SVN
Resolution:   |  Keywords: 
 Stage:  Accepted | Has_patch:  0  
Needs_docs:  0|   Needs_tests:  0  
Needs_better_patch:  0|  
--+-
Changes (by russellm):

  * milestone:  => 1.1

Comment:

 This is a fairly big problem, but it's not going to be an easy one to fix
 - the solution may just have to be documentation to say "don't do that".

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-01-18 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner:  
Status:  new  | Milestone:  post-1.0
 Component:  ORM aggregation  |   Version:  SVN 
Resolution:   |  Keywords:  
 Stage:  Accepted | Has_patch:  0   
Needs_docs:  0|   Needs_tests:  0   
Needs_better_patch:  0|  
--+-
Changes (by anonymous):

 * cc: flo...@gmail.com (added)

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-01-18 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner:  
Status:  new  | Milestone:  post-1.0
 Component:  ORM aggregation  |   Version:  SVN 
Resolution:   |  Keywords:  
 Stage:  Accepted | Has_patch:  0   
Needs_docs:  0|   Needs_tests:  0   
Needs_better_patch:  0|  
--+-
Old description:

> Annotating across multiple tables results in wrong answers. i.e.
>
> In [110]: total =
> Branch.objects.all().annotate(total=Sum('center__client__loan__amount'))
>
> In [111]: total[0].total
> Out[111]: 3433000
>
> In [112]: repaid =
> Branch.objects.all().annotate(repaid=Sum('center__client__loan__payment_schedule__payments__principal'))
>
> In [113]: repaid[0].repaid
> Out[113]: 1976320.0
>
> In [114]: both =
> Branch.objects.all().annotate(total=Sum('center__client__loan__amount'),repaid=Sum('center__client__loan__payment_schedule__payments__principal'))
>
> In [115]: both[0].repaid
> Out[115]: 1976320.0
>
> In [116]: both[0].total
> Out[116]: 98816000
>   ^^^
>
> Compare the output of total in 116 vs. 111 (the correct answer).

New description:

 Annotating across multiple tables results in wrong answers. i.e.

 {{{
 In [110]: total =
 Branch.objects.all().annotate(total=Sum('center__client__loan__amount'))

 In [111]: total[0].total
 Out[111]: 3433000

 In [112]: repaid =
 
Branch.objects.all().annotate(repaid=Sum('center__client__loan__payment_schedule__payments__principal'))

 In [113]: repaid[0].repaid
 Out[113]: 1976320.0

 In [114]: both =
 
Branch.objects.all().annotate(total=Sum('center__client__loan__amount'),repaid=Sum('center__client__loan__payment_schedule__payments__principal'))

 In [115]: both[0].repaid
 Out[115]: 1976320.0

 In [116]: both[0].total
 Out[116]: 98816000
   ^^^
 }}}

 Compare the output of total in 116 vs. 111 (the correct answer).

Comment (by ubernostrum):

 (formatting)

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-01-18 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner:  
Status:  new  | Milestone:  post-1.0
 Component:  ORM aggregation  |   Version:  SVN 
Resolution:   |  Keywords:  
 Stage:  Accepted | Has_patch:  0   
Needs_docs:  0|   Needs_tests:  0   
Needs_better_patch:  0|  
--+-
Comment (by svsha...@intellecap.net):

 if you unzip agg_test.tar.gz, start a django shell in the project and run
 count.py in the shell, you will see the error being reproduced.

 cheers
 Sid

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #10060: Multiple table annotation failure

2009-01-17 Thread Django
#10060: Multiple table annotation failure
--+-
  Reporter:  svsha...@intellecap.net  | Owner:  
Status:  new  | Milestone:  post-1.0
 Component:  ORM aggregation  |   Version:  SVN 
Resolution:   |  Keywords:  
 Stage:  Accepted | Has_patch:  0   
Needs_docs:  0|   Needs_tests:  0   
Needs_better_patch:  0|  
--+-
Changes (by russellm):

  * needs_better_patch:  => 0
  * stage:  Unreviewed => Accepted
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 It would help a great deal if you gave us the actual models and sample
 data. You have highlighted an inconsistency, but you haven't given us the
 ability to reproduce the failure.

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



[Django] #10060: Multiple table annotation failure

2009-01-17 Thread Django
#10060: Multiple table annotation failure
-+--
 Reporter:  svsha...@intellecap.net  |  Status:  new
Milestone:  post-1.0 |   Component:  ORM aggregation
  Version:  SVN  |Keywords: 
Stage:  Unreviewed   |   Has_patch:  0  
-+--
 Annotating across multiple tables results in wrong answers. i.e.

 In [110]: total =
 Branch.objects.all().annotate(total=Sum('center__client__loan__amount'))

 In [111]: total[0].total
 Out[111]: 3433000

 In [112]: repaid =
 
Branch.objects.all().annotate(repaid=Sum('center__client__loan__payment_schedule__payments__principal'))

 In [113]: repaid[0].repaid
 Out[113]: 1976320.0

 In [114]: both =
 
Branch.objects.all().annotate(total=Sum('center__client__loan__amount'),repaid=Sum('center__client__loan__payment_schedule__payments__principal'))

 In [115]: both[0].repaid
 Out[115]: 1976320.0

 In [116]: both[0].total
 Out[116]: 98816000
   ^^^

 Compare the output of total in 116 vs. 111 (the correct answer).

-- 
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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---