Opened 4 years ago

Last modified 4 years ago

#31446 closed Bug

Annotate with ExpressionWrapper gives wrong result on date field — at Version 1

Reported by: Gerben Morsink Owned by: nobody
Component: Database layer (models, ORM) Version: 2.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Gerben Morsink)

from django.db.models import DateTimeField, ExpressionWrapper, F

When doing:

{{{Ticket.objects.annotate(

notify_date=ExpressionWrapper(

F('date') - F('notify_before_in_days'), output_field=DateField()))

}}}
With on Ticket a modelfield: date = models.DateField() will yield wrong results if notify_before_in_days passes through the month boundary.
E.g. If date is 9th of April and notify_before_in_days = 10, it will yield: 20200399 for notify_date, instead of 20200331.

Database is MySQL 8.0.19-0ubuntu0.19.10.3 - (Ubuntu), Django version is 2.2.10.

Change History (1)

comment:1 by Gerben Morsink, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top