summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2025-09-11 19:44:29 +0100
committerJacob Walls <jacobtylerwalls@gmail.com>2025-09-16 20:58:40 -0400
commit2063c88c34566f46ad120c5b37c9926ffd3f10a6 (patch)
treec70e7f10f70121b71622f3c91135cb5f64abd6aa
parent2336d5d33a73032bd0d0745b21207ffc01f02b8e (diff)
Fixed #36606 -- Optimized QuerySet.values_list(flat=True) without fields.
-rw-r--r--django/db/models/query.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 0de5787f42..bd79e4bf36 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1416,11 +1416,14 @@ class QuerySet(AltersData):
def values_list(self, *fields, flat=False, named=False):
if flat and named:
raise TypeError("'flat' and 'named' can't be used together.")
- if flat and len(fields) > 1:
- raise TypeError(
- "'flat' is not valid when values_list is called with more than one "
- "field."
- )
+ if flat:
+ if len(fields) > 1:
+ raise TypeError(
+ "'flat' is not valid when values_list is called with more than one "
+ "field."
+ )
+ elif not fields:
+ fields = [self.model._meta.concrete_fields[0].attname]
field_names = {f: False for f in fields if not hasattr(f, "resolve_expression")}
_fields = []