[Django] #28497: filtering with non-values QuerySet crashes

21 views
Skip to first unread message

Django

unread,
Aug 15, 2017, 2:35:58 AM8/15/17
to django-...@googlegroups.com
#28497: filtering with non-values QuerySet crashes
-------------------------------------+-------------------------------------
Reporter: Sergey | Owner: nobody
Fedoseev |
Type: Bug | Status: new
Component: Database | Version: 1.11
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 |
-------------------------------------+-------------------------------------
{{{
PersonSkill.objects.filter(skill=Skill.objects.all()[:1])

ProgrammingError: ОШИБКА: подзапрос должен вернуть только один столбец
(subquery should return single column)
LINE 1: ...nskill" WHERE "test_app_personskill"."skill_id" = (SELECT "t...
}}}


Introduced in ec50937bcbe160e658ef881021402e156beb0eaf.

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

Django

unread,
Aug 15, 2017, 10:09:36 AM8/15/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* version: 1.11 => master
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


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

Django

unread,
Aug 15, 2017, 4:40:05 PM8/15/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* cc: Simon Charette (added)


Comment:

We should try to error out with a more appropriate message but I don't
think we ever officially supported passing a queryset to an `__exact`
lookup. I vaguely remember a ticket about it but I can't find it anymore.

I think you should be using an `__in` lookup instead as your query will
fail with `more than one row returned by a subquery used as an expression`
as soon as the table backing up your ` Skill` model has more than two
rows.

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

Django

unread,
Aug 21, 2017, 8:40:02 AM8/21/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Maybe #25284 is the related ticket Simon thought of.

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

Django

unread,
Aug 21, 2017, 10:50:49 AM8/21/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

That's the ticket I was referring to, thanks for looking that up Tim!

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

Django

unread,
Sep 7, 2017, 1:28:28 PM9/7/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Here's a regression test. It's not clear to me why this shouldn't be
allowed. What should the error message say?
{{{ #!diff
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py
index 25098af..7eeaa26 100644
--- a/tests/lookup/tests.py
+++ b/tests/lookup/tests.py
@@ -138,6 +138,12 @@ class LookupTests(TestCase):
with self.assertNumQueries(expected_num_queries):
self.assertEqual(Author.objects.in_bulk(authors.keys()),
authors)

+ def test_filter_with_sliced(self):
+ self.assertSequenceEqual(
+ Article.objects.filter(author=Author.objects.all()[:1]),
+ [self.a4, self.a2, self.a3, self.a1],
+ )
+
def test_values(self):
# values() returns a list of dictionaries instead of object
instances --
# and you can specify which fields you want to retrieve.
}}}

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

Django

unread,
Sep 7, 2017, 1:33:42 PM9/7/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Simon Charette):

> What should the error message say?

That `__in` should be used with multiple elements or a single model
instance should be passed? Maybe we could fix the issue and officialize
and support as well.

Any thoughts Sergey?

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

Django

unread,
Sep 10, 2017, 11:56:11 AM9/10/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Sergey Fedoseev):

Replying to [comment:5 Tim Graham]:


> It's not clear to me why this shouldn't be allowed.

+1

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

Django

unread,
Oct 16, 2017, 11:39:01 AM10/16/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------
Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | 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 Tim Graham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9247 PR]

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

Django

unread,
Oct 16, 2017, 3:40:31 PM10/16/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------

Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | Resolution: fixed
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 Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"1b73ccc4bf78af905f72f4658cf463f38ebf7b97" 1b73ccc4]:
{{{
#!CommitTicketReference repository=""
revision="1b73ccc4bf78af905f72f4658cf463f38ebf7b97"
Fixed #28497 -- Restored the ability to use sliced QuerySets with __exact.

Regression in ec50937bcbe160e658ef881021402e156beb0eaf.

Thanks Simon Charette for review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28497#comment:9>

Django

unread,
Oct 16, 2017, 3:40:31 PM10/16/17
to django-...@googlegroups.com
#28497: QuerySet.filter() with a sliced QuerySet crashes
-------------------------------------+-------------------------------------

Reporter: Sergey Fedoseev | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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

In [changeset:"9b3b7804d2408171cc365ad1f34402ef10d3a6b5" 9b3b7804]:
{{{
#!CommitTicketReference repository=""
revision="9b3b7804d2408171cc365ad1f34402ef10d3a6b5"
[2.0.x] Fixed #28497 -- Restored the ability to use sliced QuerySets with
__exact.

Regression in ec50937bcbe160e658ef881021402e156beb0eaf.

Thanks Simon Charette for review.

Backport of 1b73ccc4bf78af905f72f4658cf463f38ebf7b97 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28497#comment:10>

Reply all
Reply to author
Forward
0 new messages