#29166: in lookup doesn't work with lists in a When clause
-------------------------------------+-------------------------------------
Reporter: Matthew Pava | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: lookup in | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Matthew Pava:
Old description:
> 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.
New description:
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.
I have also not verified this issue in other `Expression`s in the ORM.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29166#comment:1>
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/064.c9b3904d8ff9d65ea4efbfaa851b5472%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.