mirror of https://github.com/django/django.git
Fixed #27800 -- Fixed QuerySet.annotate(Length(...)).distinct() crash.
This commit is contained in:
parent
84126f2789
commit
ac5f886c56
1
AUTHORS
1
AUTHORS
|
@ -456,6 +456,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Leo Shklovskii
|
Leo Shklovskii
|
||||||
Leo Soto <leo.soto@gmail.com>
|
Leo Soto <leo.soto@gmail.com>
|
||||||
lerouxb@gmail.com
|
lerouxb@gmail.com
|
||||||
|
Lex Berezhny <lex@damoti.com>
|
||||||
Liang Feng <hutuworm@gmail.com>
|
Liang Feng <hutuworm@gmail.com>
|
||||||
limodou
|
limodou
|
||||||
Loek van Gent <loek@barakken.nl>
|
Loek van Gent <loek@barakken.nl>
|
||||||
|
|
|
@ -1329,7 +1329,12 @@ class Query:
|
||||||
"querying. If it is a GenericForeignKey, consider "
|
"querying. If it is a GenericForeignKey, consider "
|
||||||
"adding a GenericRelation." % name
|
"adding a GenericRelation." % name
|
||||||
)
|
)
|
||||||
model = field.model._meta.concrete_model
|
try:
|
||||||
|
model = field.model._meta.concrete_model
|
||||||
|
except AttributeError:
|
||||||
|
# QuerySet.annotate() may introduce fields that aren't
|
||||||
|
# attached to a model.
|
||||||
|
model = None
|
||||||
else:
|
else:
|
||||||
# We didn't find the current field, so move position back
|
# We didn't find the current field, so move position back
|
||||||
# one step.
|
# one step.
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.db.models import (
|
||||||
BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func,
|
BooleanField, CharField, Count, DateTimeField, ExpressionWrapper, F, Func,
|
||||||
IntegerField, NullBooleanField, Q, Sum, Value,
|
IntegerField, NullBooleanField, Q, Sum, Value,
|
||||||
)
|
)
|
||||||
from django.db.models.functions import Lower
|
from django.db.models.functions import Length, Lower
|
||||||
from django.test import TestCase, skipUnlessDBFeature
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
|
@ -205,6 +205,11 @@ class NonAggregateAnnotationTestCase(TestCase):
|
||||||
).distinct('test_alias')
|
).distinct('test_alias')
|
||||||
self.assertEqual(len(people2), 1)
|
self.assertEqual(len(people2), 1)
|
||||||
|
|
||||||
|
lengths = Employee.objects.annotate(
|
||||||
|
name_len=Length('first_name'),
|
||||||
|
).distinct('name_len').values_list('name_len', flat=True)
|
||||||
|
self.assertSequenceEqual(lengths, [3, 7, 8])
|
||||||
|
|
||||||
def test_filter_annotation(self):
|
def test_filter_annotation(self):
|
||||||
books = Book.objects.annotate(
|
books = Book.objects.annotate(
|
||||||
is_book=Value(1, output_field=IntegerField())
|
is_book=Value(1, output_field=IntegerField())
|
||||||
|
|
Loading…
Reference in New Issue