Opened 5 years ago
Last modified 5 years ago
#31446 closed Bug
Annotate with ExpressionWrapper gives wrong result on date field — at Initial Version
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
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.