I believe the fix would be as easy as patching these lines:
https://github.com/django/django/blob/41725602afebe2ddb018b99afe134384cc3bf69e/django/db/models/query.py#L699-L703
To include `and field_name not in self.query.distinct_fields`
--
Ticket URL: <https://code.djangoproject.com/ticket/31918>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* keywords: in_bulk, distinct, queryset => in_bulk distinct queryset
* type: Bug => New feature
* easy: 1 => 0
* stage: Unreviewed => Accepted
Comment:
Feature request makes sense, PR with tests is welcome.
--
Ticket URL: <https://code.djangoproject.com/ticket/31918#comment:1>
* owner: nobody => Kaustubh
* status: new => assigned
Comment:
I'd like to work on this
--
Ticket URL: <https://code.djangoproject.com/ticket/31918#comment:2>
Comment (by Wolph):
I was planning to create a PR over the weekend, but you're more than
welcome to give it a try :)
--
Ticket URL: <https://code.djangoproject.com/ticket/31918#comment:3>
Comment (by Kaustubh):
Replying to [comment:3 Wolph]:
> I was planning to create a PR over the weekend, but you're more than
welcome to give it a try :)
Thanks, I'll inform you if I get stuck (I'm a newcomer to open source)
--
Ticket URL: <https://code.djangoproject.com/ticket/31918#comment:4>
Comment (by Kaustubh):
Linked PR : https://github.com/django/django/pull/13338
--
Ticket URL: <https://code.djangoproject.com/ticket/31918#comment:5>
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/31918#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"b9be11d44265308863e4e8cfb458cd3605091452" b9be11d4]:
{{{
#!CommitTicketReference repository=""
revision="b9be11d44265308863e4e8cfb458cd3605091452"
Fixed #31918 -- Allowed QuerySet.in_bulk() to fetch on a single distinct
field.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31918#comment:7>