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 ExpressionWrapper() doesn't respect output_field when combining DateField and timedelta on PostgreSQL and MySQL. Matthieu Rigal "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`..." Bug new Database layer (models, ORM) dev Normal Josh Smeaton David Sanders Accepted 0 0 0 0 0 0