[Django] #26071: IN queries inside conditional case expressions crashes on django 1.8

39 views
Skip to first unread message

Django

unread,
Jan 11, 2016, 11:56:13 AM1/11/16
to django-...@googlegroups.com
#26071: IN queries inside conditional case expressions crashes on django 1.8
----------------------------------------------+--------------------
Reporter: albertein | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
When making a IN filter expression inside a conditional case expression
django crashes with the following exception:

AttributeError: 'SubqueryConstraint' object has no attribute 'lhs'

The stacktrace looks like:

lib/python2.7/site-packages/django/db/models/query.py line 794 in
annotate
obj.query.add_annotation(annotation, alias, is_summary=False)
lib/python2.7/site-packages/django/db/models/sql/query.py line 983 in
add_annotation
summarize=is_summary)
lib/python2.7/site-packages/django/db/models/aggregates.py line 21 in
resolve_expression
if c.source_expressions[0].contains_aggregate and not summarize:
lib/python2.7/site-packages/django/utils/functional.py line 59 in
__get__
res = instance.__dict__[self.name] = self.func(instance)
lib/python2.7/site-packages/django/db/models/expressions.py line 179
in contains_aggregate
if expr and expr.contains_aggregate:
lib/python2.7/site-packages/django/utils/functional.py line 59 in
__get__
res = instance.__dict__[self.name] = self.func(instance)
lib/python2.7/site-packages/django/db/models/expressions.py line 179
in contains_aggregate
if expr and expr.contains_aggregate:
lib/python2.7/site-packages/django/utils/functional.py line 59 in
__get__
res = instance.__dict__[self.name] = self.func(instance)
lib/python2.7/site-packages/django/db/models/sql/where.py line 324 in
contains_aggregate
return self._contains_aggregate(self)
lib/python2.7/site-packages/django/db/models/sql/where.py line 320 in
_contains_aggregate
return any(cls._contains_aggregate(c) for c in obj.children)
lib/python2.7/site-packages/django/db/models/sql/where.py line 320 in
<genexpr>
return any(cls._contains_aggregate(c) for c in obj.children)
lib/python2.7/site-packages/django/db/models/sql/where.py line 319 in
_contains_aggregate
return getattr(obj.lhs, 'contains_aggregate', False) or
getattr(obj.rhs, 'contains_aggregate', False)
AttributeError: 'SubqueryConstraint' object has no attribute 'lhs'

This error is already fixed on django 1.9 branch. The problem was fixed
with this commit:

https://github.com/django/django/commit/afe0bb7b13bb8dc4370f32225238012c873b0ee3
#diff-73bc0dcb1a1c931adcf1d344abca22ffR180

I'll create a PR with the changes from that commit that fixes the issue,
not sure if the entire commit can be (or should be) backported to 1.8

--
Ticket URL: <https://code.djangoproject.com/ticket/26071>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 11, 2016, 11:57:58 AM1/11/16
to django-...@googlegroups.com
#26071: IN queries inside conditional case expressions crashes on django 1.8
-------------------------------------+-------------------------------------

Reporter: albertein | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by albertein):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

New description:

The stacktrace looks like:

https://github.com/django/django/commit/afe0bb7b13bb8dc4370f32225238012c873b0ee3
#diff-73bc0dcb1a1c931adcf1d344abca22ffR180

UPDATE: PR with only the changes needed and its test:
https://github.com/django/django/pull/5967

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26071#comment:1>

Django

unread,
Jan 11, 2016, 12:03:09 PM1/11/16
to django-...@googlegroups.com
#26071: IN queries inside conditional case expressions crashes on django 1.8
-------------------------------------+-------------------------------------

Reporter: albertein | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | 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 albertein:

Old description:

> UPDATE: PR with only the changes needed and its test:
> https://github.com/django/django/pull/5967

New description:

The stacktrace looks like:

https://github.com/django/django/commit/afe0bb7b13bb8dc4370f32225238012c873b0ee3
#diff-73bc0dcb1a1c931adcf1d344abca22ffR180

UPDATE: PR with only the changes needed and its test:
https://github.com/django/django/pull/5967

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26071#comment:2>

Django

unread,
Jan 11, 2016, 12:03:24 PM1/11/16
to django-...@googlegroups.com
#26071: IN queries inside conditional case expressions crashes on django 1.8
-------------------------------------+-------------------------------------

Reporter: albertein | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | 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 albertein:

Old description:

> When making a IN filter expression inside a conditional case expression

> UPDATE: PR with only the changes needed and its test:
> https://github.com/django/django/pull/5967

New description:

When making a IN filter expression inside a conditional case expression

The stacktrace looks like:

https://github.com/django/django/commit/afe0bb7b13bb8dc4370f32225238012c873b0ee3
#diff-73bc0dcb1a1c931adcf1d344abca22ffR180

UPDATE: PR with only the changes needed and its test:
https://github.com/django/django/pull/5967

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26071#comment:3>

Django

unread,
Jan 11, 2016, 1:04:46 PM1/11/16
to django-...@googlegroups.com
#26071: IN queries inside conditional case expressions crashes on django 1.8
-------------------------------------+-------------------------------------
Reporter: albertein | Owner: timgraham
Type: Bug | Status: assigned

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* owner: nobody => timgraham
* status: new => assigned
* has_patch: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26071#comment:4>

Django

unread,
Jan 11, 2016, 2:13:06 PM1/11/16
to django-...@googlegroups.com
#26071: IN queries inside conditional case expressions crashes on django 1.8
-------------------------------------+-------------------------------------
Reporter: albertein | Owner:
Type: Bug | Status: new

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* owner: timgraham =>
* needs_better_patch: 0 => 1
* status: assigned => new


Comment:

The new test needs to be fixed on Oracle: `ORA-00932: inconsistent
datatypes: expected - got BLOB`.

--
Ticket URL: <https://code.djangoproject.com/ticket/26071#comment:5>

Django

unread,
Jan 13, 2016, 8:40:23 AM1/13/16
to django-...@googlegroups.com
#26071: IN queries inside conditional case expressions crashes on django 1.8
-------------------------------------+-------------------------------------
Reporter: albertein | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* owner: => Tim Graham <timograham@…>
* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"5b3c66d8b64add684489f5010e43de73e7acdd04" 5b3c66d]:
{{{
#!CommitTicketReference repository=""
revision="5b3c66d8b64add684489f5010e43de73e7acdd04"
[1.8.x] Fixed #26071 -- Fixed crash with __in lookup in a Case expression.

Partial backport of afe0bb7b13bb8dc4370f32225238012c873b0ee3 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26071#comment:6>

Django

unread,
Jan 13, 2016, 8:54:02 AM1/13/16
to django-...@googlegroups.com
#26071: IN queries inside conditional case expressions crashes on django 1.8
-------------------------------------+-------------------------------------
Reporter: albertein | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"16a52cff3250269d8461b5b2877d0929e463adcd" 16a52cf]:
{{{
#!CommitTicketReference repository=""
revision="16a52cff3250269d8461b5b2877d0929e463adcd"
[1.9.x] Refs #26071 -- Added test for __in lookup in a Case expression.

Forwardport of 5b3c66d8b64add684489f5010e43de73e7acdd04 from stable/1.8.x
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26071#comment:7>

Django

unread,
Jan 13, 2016, 9:32:39 AM1/13/16
to django-...@googlegroups.com
#26071: IN queries inside conditional case expressions crashes on django 1.8
-------------------------------------+-------------------------------------
Reporter: albertein | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"cca151d196d520f799d3517a9719d03c0c8c9d8a" cca151d1]:
{{{
#!CommitTicketReference repository=""
revision="cca151d196d520f799d3517a9719d03c0c8c9d8a"


Refs #26071 -- Added test for __in lookup in a Case expression.

Forwardport of 5b3c66d8b64add684489f5010e43de73e7acdd04 from stable/1.8.x
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26071#comment:8>

Reply all
Reply to author
Forward
0 new messages