mirror of
https://github.com/django/django.git
synced 2025-08-01 17:42:56 +00:00
Fixed #14476 -- Fixed resolution of automatically generated annotation names so e.g. filtering based on them works. Thanks dirleyls for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16252 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
803a454aef
commit
15793309e1
2 changed files with 35 additions and 8 deletions
|
@ -827,3 +827,30 @@ class AggregationTests(TestCase):
|
|||
Book.objects.aggregate(Variance('price', sample=True)),
|
||||
{'price__variance': Approximate(700.53, 2)}
|
||||
)
|
||||
|
||||
def test_filtering_by_annotation_name(self):
|
||||
# Regression test for #14476
|
||||
|
||||
# The name of the explicitly provided annotation name in this case
|
||||
# poses no problem
|
||||
qs = Author.objects.annotate(book_cnt=Count('book')).filter(book_cnt=2)
|
||||
self.assertQuerysetEqual(
|
||||
qs,
|
||||
['Peter Norvig'],
|
||||
lambda b: b.name
|
||||
)
|
||||
# Neither in this case
|
||||
qs = Author.objects.annotate(book_count=Count('book')).filter(book_count=2)
|
||||
self.assertQuerysetEqual(
|
||||
qs,
|
||||
['Peter Norvig'],
|
||||
lambda b: b.name
|
||||
)
|
||||
# This case used to fail because the ORM couldn't resolve the
|
||||
# automatically generated annotation name `book__count`
|
||||
qs = Author.objects.annotate(Count('book')).filter(book__count=2)
|
||||
self.assertQuerysetEqual(
|
||||
qs,
|
||||
['Peter Norvig'],
|
||||
lambda b: b.name
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue