#31446: Annotate with ExpressionWrapper gives wrong result on date field
-------------------------------------+-------------------------------------
Reporter: Gerben Morsink | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.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
-------------------------------------+-------------------------------------
Description changed by Gerben Morsink:
Old 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.
New 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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/31446#comment:1>
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/064.c50b05fa81fac9e25a5dbdf875fb3fb6%40djangoproject.com.