#13589: Annotate returns empty set without value arguments ---------------------------+------------------------------------------------ Reporter: adamnelson | Owner: nobody Status: new | Milestone: Component: Uncategorized | Version: 1.1 Keywords: | Stage: Unreviewed Has_patch: 0 | ---------------------------+------------------------------------------------ With a class referring to itself via a foreign key, annotate does not correctly return results from a filter unless the values to group by are in the queryset. This is either counter to the documentation or an interface bug:
http://docs.djangoproject.com/en/dev/topics/db/aggregation/#filtering-on- annotations {{{ class PageEmailLink(models.Model): parent = models.ForeignKey('self', null=True, blank=True, related_name='child') # Other fields like url, level_deep, etc... from django.db.models import Count PageEmailLink.objects.annotate(num_emails=Count('parent')).filter(num_emails__gt=1) [] PageEmailLink.objects.values('parent').annotate(num_emails=Count('parent')).filter(num_emails__gt=1) [{'num_emails': 2, 'parent': 67}, {'num_emails': 2, 'parent': 70}, {'num_emails': 2, 'parent': 75}, {'num_emails': 2, 'parent': 83}, {'num_emails': 2, 'parent': 144446}, {'num_emails': 2, 'parent': 144448}, {'num_emails': 2, 'parent': 144452}, {'num_emails': 2, 'parent': 144453}, {'num_emails': 2, 'parent': 144454}, {'num_emails': 2, 'parent': 144456}, {'num_emails': 2, 'parent': 144457}, {'num_emails': 2, 'parent': 144459}, {'num_emails': 2, 'parent': 144493}, {'num_emails': 2, 'parent': 144495}, {'num_emails': 2, 'parent': 144497}, {'num_emails': 2, 'parent': 144499}, {'num_emails': 2, 'parent': 144500}, {'num_emails': 2, 'parent': 144502}, {'num_emails': 2, 'parent': 144507}, {'num_emails': 2, 'parent': 144508}, '...(remaining elements truncated)...'] PageEmailLink.objects.filter(parent=67) [<PageEmailLink: http://www.dnelist.com/u/56c372cfa20fccb51b2325ce55496d265 5 levels deep>, <PageEmailLink: http://www.dnelist.com/u/56c372cfa20fccb51b2325ce55496d265 5 levels deep>] }}} -- Ticket URL: <http://code.djangoproject.com/ticket/13589> Django <http://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 post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.
