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.
* version: 1.11 => master
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28497#comment:1>
* 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>
Comment (by Tim Graham):
Maybe #25284 is the related ticket Simon thought of.
--
Ticket URL: <https://code.djangoproject.com/ticket/28497#comment:3>
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>
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>
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>
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>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/9247 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/28497#comment:8>
* 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>
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>