Changes between Version 1 and Version 2 of Ticket #32573


Ignore:
Timestamp:
Mar 19, 2021, 1:30:24 PM (3 years ago)
Author:
Florian Demmer
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32573 – Description

    v1 v2  
    11The optimization to use BETWEEN instead of the EXTRACT operation in [https://github.com/django/django/blob/main/django/db/models/lookups.py#L540 YearLookup] is also registered for the [https://github.com/django/django/blob/main/django/db/models/functions/datetime.py#L167 "__iso_year" lookup], which breaks the functionality provided by [https://docs.djangoproject.com/en/2.2/ref/models/database-functions/#django.db.models.functions.ExtractIsoYear ExtractIsoYear] when used via the lookup.
    22
    3 This has unfortunately been broken ever since ExtractIsoYear was introduced in Django 2.2 via #28649 and wasn't easy to track down since ExtractIsoYear when used by itself eg. in an annotation works perfectly fine. Just when using the lookup in a filter, the optimization is used (even when explicitly using an annotation):
     3This has unfortunately been broken ever since ExtractIsoYear was introduced in [https://docs.djangoproject.com/en/2.2/ref/models/querysets/#iso-year Django 2.2] via #28649 and wasn't easy to track down since ExtractIsoYear when used by itself eg. in an annotation works perfectly fine. Just when using the lookup in a filter, the optimization is used (even when explicitly using an annotation):
    44
    55{{{
     
    1515
    1616# implicit lookup uses BETWEEN
    17 print(DTModel.objects.filter(start_date__iso_year=2020).only('id').query)
     17>>> print(DTModel.objects.filter(start_date__iso_year=2020).only('id').query)
    1818SELECT "db_functions_dtmodel"."id" FROM "db_functions_dtmodel" WHERE "db_functions_dtmodel"."start_date" BETWEEN 2020-01-01 AND 2020-12-31
    1919}}}
Back to Top