1
0
mirror of https://github.com/django/django.git synced 2025-10-29 08:36:09 +00:00

Fixed #31918 -- Allowed QuerySet.in_bulk() to fetch on a single distinct field.

This commit is contained in:
Kaustubh
2020-08-22 11:23:50 +05:30
committed by Mariusz Felisiak
parent 547a07fa7e
commit b9be11d442
4 changed files with 33 additions and 3 deletions

View File

@@ -699,7 +699,8 @@ class QuerySet:
if (
field_name != 'pk' and
not opts.get_field(field_name).unique and
field_name not in unique_fields
field_name not in unique_fields and
not self.query.distinct_fields == (field_name,)
):
raise ValueError("in_bulk()'s field_name must be a unique field but %r isn't." % field_name)
if id_list is not None: