diff options
| author | Simon Charette <simon.charette@zapier.com> | 2019-05-20 18:53:13 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-05-21 07:11:26 +0200 |
| commit | 4d1420947e79bc89d266229feea305294ec896ee (patch) | |
| tree | 665c73485aabb065f71e80452bf1898c0ab544b7 /tests/db_functions/datetime | |
| parent | 1d0bab0bfd77edcf1228d45bf654457a8ff1890d (diff) | |
Fixed #30494 -- Disabled __year lookup optimization for indirect values.
The previous heuristics were naively enabling the BETWEEN optimization on
successful cast of the first rhs SQL params to an integer while it was
not appropriate for a lot of database resolved expressions.
Thanks Alexey Chernov for the report.
Diffstat (limited to 'tests/db_functions/datetime')
| -rw-r--r-- | tests/db_functions/datetime/test_extract_trunc.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/db_functions/datetime/test_extract_trunc.py b/tests/db_functions/datetime/test_extract_trunc.py index 2088d09d06..f62bd0f0b2 100644 --- a/tests/db_functions/datetime/test_extract_trunc.py +++ b/tests/db_functions/datetime/test_extract_trunc.py @@ -4,7 +4,8 @@ import pytz from django.conf import settings from django.db.models import ( - DateField, DateTimeField, IntegerField, Max, OuterRef, Subquery, TimeField, + DateField, DateTimeField, F, IntegerField, Max, OuterRef, Subquery, + TimeField, ) from django.db.models.functions import ( Extract, ExtractDay, ExtractHour, ExtractIsoYear, ExtractMinute, @@ -108,6 +109,14 @@ class DateFunctionTests(TestCase): query_string = str(qs.query).lower() self.assertEqual(query_string.count(' between '), 1) self.assertEqual(query_string.count('extract'), 0) + # an expression rhs cannot use the between optimization. + qs = DTModel.objects.annotate( + start_year=ExtractYear('start_datetime'), + ).filter(end_datetime__year=F('start_year') + 1) + self.assertEqual(qs.count(), 1) + query_string = str(qs.query).lower() + self.assertEqual(query_string.count(' between '), 0) + self.assertEqual(query_string.count('extract'), 3) def test_extract_year_greaterthan_lookup(self): start_datetime = datetime(2015, 6, 15, 14, 10) |
