Re: [Django] #37171: Targeting a subquery with __exact requires limiting to one result even when wrapped by explicit Subquery

2 views
Skip to first unread message

Django

unread,
Jun 16, 2026, 10:37:20 AM (11 days ago) Jun 16
to django-...@googlegroups.com
#37171: Targeting a subquery with __exact requires limiting to one result even when
wrapped by explicit Subquery
-------------------------------------+-------------------------------------
Reporter: Mark Baird | Owner: (none)
Type: Bug | Status: closed
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Mark Baird):

I see. The addition of [:1] in the subquery does fix it, thanks for that.
So even if this isn't a bug, I still think the breaking change should be
mentioned in the Django changelog so people running into this can see that
it is an intended change? The ticket you reference seems to be
specifically for composite primary keys, which I'm not using here at all,
so it is certainly not obvious to me that the change in that ticket would
have caused this change in behavior.
--
Ticket URL: <https://code.djangoproject.com/ticket/37171#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 16, 2026, 10:49:20 AM (11 days ago) Jun 16
to django-...@googlegroups.com
#37171: Targeting a subquery with __exact requires limiting to one result even when
wrapped by explicit Subquery
-------------------------------------+-------------------------------------
Reporter: Mark Baird | Owner: (none)
Type: Bug | Status: closed
Component: Database layer | Version: 6.0
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):

In this case the error message is clear ("an exact lookup must be limited
to one result"), so I'm not sure a release note would provide additional
useful information. It would be a different situation if this were a
breaking change, but Django is just behaving as
[https://docs.djangoproject.com/en/dev/ref/models/expressions/#limiting-
the-subquery-to-a-single-row documented], and in general we don't document
bugfixes that bring Django's behavior in greater alignment with its docs.
--
Ticket URL: <https://code.djangoproject.com/ticket/37171#comment:3>
Reply all
Reply to author
Forward
0 new messages