﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31506	Clarify that ExpressionWrapper is not the tool to use when coping with DateField and timedelta arithmetic quirks on PostgreSQL and MySQL	Matthieu Rigal	Hwayoung Cha	"The problem actually exists since 1.11 to 2.2, probably also in 3.X. Lastly tested with Django 2.2.12 and psycopg2 2.8.3

Take the model

{{{
StartModel(models.Model):
    start = models.DateField()
}}}

When working on the queryset in this way:

{{{
next_segments = StartModel.objects.filter('start__gt': OuterRef('start')).order_by('start')
qs = StartModel.objects.annotate(
            end=ExpressionWrapper(
                Subquery(next_segments.values('start')[:1]) - datetime.timedelta(days=1),
                output_field=DateField(),
            )
        )
}}}

`qs.first().end` is of type `datetime`, not `date`..."	Cleanup/optimization	closed	Documentation	dev	Normal	fixed		Josh Smeaton David Sanders	Ready for checkin	1	0	0	0	0	0
