#33635: Django 3.2.13 raises ProgrammingError "can't adapt type 'LessThan'"
-------------------------------------+-------------------------------------
               Reporter:  Shaheed    |          Owner:  nobody
  Haque                              |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33635>
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/0107018018236357-9e769ac4-70e3-4df7-b9ee-5a1b3cc19133-000000%40eu-central-1.amazonses.com.

Reply via email to