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.
Old description:
New description:
I have also not verified this issue in other `Expression`s in the ORM.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29166#comment:1>
* status: new => assigned
* owner: nobody => felixxm
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
Regression in 19b2dfd1bfe7fd716dd3d8bfa5f972070d83b42f.
--
Ticket URL: <https://code.djangoproject.com/ticket/29166#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/9734 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29166#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29166#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"54f80430be4a9adf1fc00b4ca17547415fafc69b" 54f8043]:
{{{
#!CommitTicketReference repository=""
revision="54f80430be4a9adf1fc00b4ca17547415fafc69b"
Fixed #29166 -- Fixed crash in When() expression with a list argument.
Thanks Matthew Pava for the report and Tim Graham and Carlton Gibson for
reviews.
Regression in 19b2dfd1bfe7fd716dd3d8bfa5f972070d83b42f.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29166#comment:5>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"10a20e4b37da94fd55b4e9a13e634c2a379bd9e0" 10a20e4]:
{{{
#!CommitTicketReference repository=""
revision="10a20e4b37da94fd55b4e9a13e634c2a379bd9e0"
[2.0.x] Fixed #29166 -- Fixed crash in When() expression with a list
argument.
Thanks Matthew Pava for the report and Tim Graham and Carlton Gibson for
reviews.
Regression in 19b2dfd1bfe7fd716dd3d8bfa5f972070d83b42f.
Backport of 54f80430be4a9adf1fc00b4ca17547415fafc69b from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29166#comment:6>
Comment (by Дилян Палаузов):
{{{
diff --git a/django/db/models/expressions.py
b/django/db/models/expressions.py
+ return hash((path, output_field) + args + tuple([
+ (key, tuple(value)) if isinstance(value, list) else (key,
value)
+ for key, value in kwargs.items()
+ ]))
}}}
Aren't here the {{{[}}} and {{{]}}} superflous, as the parameter of both
{{{tuple()}}} and {{{[]}}} have to be iterable, and this the type of the
inlined {{{for}}}:
{{{
>>> tuple([(x,y) for x, y in {'a': 1, 'b':2, 'c':3}.items()])
(('a', 1), ('b', 2), ('c', 3))
>>> tuple((x,y) for x, y in {'a': 1, 'b':2, 'c':3}.items())
(('a', 1), ('b', 2), ('c', 3))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29166#comment:7>
* cc: Дилян Палаузов (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/29166#comment:8>