﻿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
33635	"Django 3.2.13 raises ProgrammingError ""can't adapt type 'LessThan'"""	Shaheed Haque	nobody	"I'm using Postgres as my db engine. I have a couple of lines of code like this:

{{{
qs = company.employee_set.annotate(past=Coalesce(LessThan(F('end_date'), Value(date.today())), Value(False)))
qs = qs.order_by(...)
return list(qs.values_list(...))
}}}

The idea is to compare ""end_date"" (a DateField which can be null) with the given Python datetime.date, i.e. in Python terms, something like this:

{{{
past = end_date < today if end_date is not None else False
}}}

This works as I expected on Django 4.0.4, but fails on 3.2.13 where is causes the **can't adapt type 'LessThan'**.  I tried a couple of other formulations of the query, including moving the **Coalesce** to ""inside"":

{{{
...annotate(past=LessThan(Coalesce(F('end_date'), Value('1999-01-01'), output_field=DateField()), Value(date.today())))
}}}

This also worked on Django 4.0.4, but failed on 3.2.13 with TypeError ""QuerySet.annotate() received non-expression(s): <django.db.models.lookups.LessThan object at ...>.""

Since a Lookup is a query expression, I assume this is a bug? Is there a workaround I might try?
"	Bug	closed	Database layer (models, ORM)	3.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
