#29166: in lookup doesn't work with lists in a When clause
-------------------------------------+-------------------------------------
Reporter: Matthew | Owner: nobody
Pava |
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords: lookup in
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have an annotation that worked fine in Django 1.11, but I just
discovered that it doesn't work with Django 2.0. The error message
reported:
`TypeError: unhashable type: 'list'`
I have an `Order` model that has a `status` and `status_date` field, and
here's the query that worked in the past (simplified):
{{{
Order.objects.annotate(
end_date=Case(
When(
status__in=[3, 2],
then=Cast(F('status_date'), DateField())
),
default=Value(timezone.now().date())
)
)
}}}
Note the list used as the arg in the `__in` lookup.
My current workaround is to use `Q` objects with the `|` operator.
{{{
Order.objects.annotate(
end_date=Case(
When(
Q(status=3) | Q(status=2),
then=Cast(F('status_date'), DateField())
),
default=Value(timezone.now().date())
)
)
}}}
Others may not find that workaround as practical.
--
Ticket URL: <https://code.djangoproject.com/ticket/29166>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.0679623894f07af3e5b0748020aadcf6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.