#36392 closed Bug (fixed)
ValueError not raised when wrong number of columns selected by subquery against composite primary key
Reported by: | Jacob Walls | Owned by: | Jacob Walls |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.2 |
Severity: | Release blocker | Keywords: | pk |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Discovered during review of #36210 that the guard for the appropriate number of columns selected in a subquery is not aware that "pk"
might represent N columns, so the ValueError
that should be raised is evaded, failing instead at the db layer.
We're just changing one type of exception to another--so this isn't terribly serious--but in the interest of standardizing what kinds of exceptions are raised during usage of the composite pk feature, starting out at release blocker?
-
tests/composite_pk/test_filter.py
diff --git a/tests/composite_pk/test_filter.py b/tests/composite_pk/test_filter.py index 16c4c2a91a..f629f85ca6 100644
a b class CompositePKFilterTests(TestCase): 207 207 [self.comment_1], 208 208 ) 209 209 210 def test_invalid_filter_by_pk_in_columns_besides_pk(self): 211 with self.assertRaisesMessage(ValueError, "must have 2 selected fields"): 212 User.objects.filter(pk__in=User.objects.values("pk", "email")).count() 213 210 214 def test_filter_by_pk_in_none(self): 211 215 with self.assertNumQueries(0): 212 216 self.assertSequenceEqual(
Postgres failure looks like:
File "/Users/.../django/django/db/backends/sqlite3/base.py", line 360, in execute return super().execute(query, params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ django.db.utils.OperationalError: sub-select returns 3 columns - expected 2
Change History (8)
comment:1 by , 2 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 2 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:3 by , 2 months ago
Has patch: | set |
---|
comment:4 by , 2 months ago
Patch needs improvement: | set |
---|
comment:5 by , 2 months ago
Patch needs improvement: | unset |
---|
comment:6 by , 2 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
PR