#30518: Multiple Count annotation with filter doesn't work properly (at least if
related modelas has same named fileds)
-------------------------------------+-------------------------------------
Reporter: farin | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords: annotate
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Lets have following models
{{{
class User(models.Model):
pass
class Subscription(models.Model):
user = models.ForeignKey(User, models.CASCADE)
valid_to = models.DateTimeField()
class SubscriptionToAuthor(models.Model):
user = models.ForeignKey(User, models.CASCADE)
valid_to = models.DateTimeField()
}}}
then annotate on only one related model works fine
{{{
# this is ok
User.objects.annotate(
subscribed_authors=Count('subscriptiontoauthor',
filter=Q(subscriptiontoauthor__valid_to__gt=now))
)
}}}
or
{{{
# this is ok
User.objects.annotate(
subscribed_newspapers=Count('subscription',
filter=Q(subscription__valid_to__gt=now))
)
}}}
but Count returns incorrect (too big) count numbers when both annotations
are used on single query set
{{{
# wrong result
User.objects.annotate(
subscribed_authors=Count('subscriptiontoauthor',
filter=Q(subscriptiontoauthor__valid_to__gt=now))
).annotate(
subscribed_newspapers=Count('subscription',
filter=Q(subscription__valid_to__gt=now))
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30518>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/048.ecf7791756af17a0a65773c7a68b950b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.