summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/models/sql/query.py2
-rw-r--r--tests/annotations/tests.py10
2 files changed, 11 insertions, 1 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index fb1f831042..39ecab2e91 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1817,7 +1817,7 @@ class Query(BaseExpression):
available = sorted(
[
*get_field_names_from_opts(opts),
- *self.annotation_select,
+ *self.annotations,
*self._filtered_relations,
]
)
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
index 8091498908..cf1eebf8d7 100644
--- a/tests/annotations/tests.py
+++ b/tests/annotations/tests.py
@@ -1539,3 +1539,13 @@ class AliasTests(TestCase):
)
with self.assertRaisesMessage(ValueError, msg):
Book.objects.alias(**{crafted_alias: FilteredRelation("authors")})
+
+ def test_values_wrong_alias(self):
+ expected_message = (
+ "Cannot resolve keyword 'alias_typo' into field. Choices are: %s"
+ )
+ alias_fields = ", ".join(
+ sorted(["my_alias"] + list(get_field_names_from_opts(Book._meta)))
+ )
+ with self.assertRaisesMessage(FieldError, expected_message % alias_fields):
+ Book.objects.alias(my_alias=F("pk")).order_by("alias_typo")