summaryrefslogtreecommitdiff
path: root/django/db/models/sql
diff options
context:
space:
mode:
authorJaeHyuck Sa <wogur981208@gmail.com>2026-01-16 00:29:25 +0900
committerJacob Walls <jacobtylerwalls@gmail.com>2026-01-16 10:28:14 -0500
commit0239e86f387127dace7273208c300b33a065e021 (patch)
treeb57524a6845b2716b4d7d6167d706d34e65a4098 /django/db/models/sql
parenta77e541d1d8766b0e7d2c4143076ef07973f5bd9 (diff)
Fixed #36352 -- Improved error message for fields excluded by prior values()/values_list() calls.
Signed-off-by: JaeHyuck Sa <wogur981208@gmail.com>
Diffstat (limited to 'django/db/models/sql')
-rw-r--r--django/db/models/sql/query.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index e3e6100f24..4be450167d 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -2585,10 +2585,17 @@ class Query(BaseExpression):
annotation_names.append(f)
selected[f] = f
elif f in self.annotations:
- raise FieldError(
- f"Cannot select the '{f}' alias. Use annotate() to "
- "promote it."
- )
+ if self.annotation_select:
+ raise FieldError(
+ f"Cannot select the '{f}' alias. It was excluded "
+ f"by a previous values() or values_list() call. "
+ f"Include '{f}' in that call to select it."
+ )
+ else:
+ raise FieldError(
+ f"Cannot select the '{f}' alias. Use annotate() "
+ f"to promote it."
+ )
else:
# Call `names_to_path` to ensure a FieldError including
# annotations about to be masked as valid choices if