#34699: Filtering on annotated TruncSecond expression gives unexpected result.
-------------------------------------+-------------------------------------
     Reporter:  Stefan               |                    Owner:  Francesco
                                     |  Panico
         Type:  Uncategorized        |                   Status:  assigned
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Natalia Bidart):

 I've been trying to understand this report to properly triage it. From the
 docs for `Trunc` and derivatives, when describing
 [https://docs.djangoproject.com/en/4.2/ref/models/database-functions
 /#datetimefield-truncation DateTimeField truncation], the example given
 shows this:

 {{{
  >>> Experiment.objects.annotate(
 ...     date=TruncDate("start_datetime"),
 ...     day=TruncDay("start_datetime", tzinfo=melb),
 ...     hour=TruncHour("start_datetime", tzinfo=melb),
 ...     minute=TruncMinute("start_datetime"),
 ...     second=TruncSecond("start_datetime"),
 ... ).values("date", "day", "hour", "minute", "second").get()
 {'date': datetime.date(2014, 6, 15),
  'day': datetime.datetime(2014, 6, 16, 0, 0,
 tzinfo=zoneinfo.ZoneInfo('Australia/Melbourne')),
  'hour': datetime.datetime(2014, 6, 16, 0, 0,
 tzinfo=zoneinfo.ZoneInfo('Australia/Melbourne')),
  'minute': 'minute': datetime.datetime(2014, 6, 15, 14, 30,
 tzinfo=timezone.utc),
  'second': datetime.datetime(2014, 6, 15, 14, 30, 50, tzinfo=timezone.utc)
 }
 }}}

 The text and examples seem to indicate that when the stored datetime is in
 a given timezone, that tz would be used in the truncation unless otherwise
 specified by the `tzinfo` param.

 @stefan, can you double check that the values for `published` are actually
 datetimes in the tz you configured you app?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34699#comment:4>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070189520d743a-102a1706-be0e-40b1-b08a-a8de06bf6be8-000000%40eu-central-1.amazonses.com.

Reply via email to