diff options
author | Simon Charette <charette.s@gmail.com> | 2023-03-25 15:22:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-25 20:22:45 +0100 |
commit | cb13792938f2c887134eb6b5164d89f8d8f9f1bd (patch) | |
tree | 508a2d0769df6a81699a4121fe07379fff27fbf6 /tests/annotations | |
parent | f5c5c571d3b87a78d005ea6f21959388d1747696 (diff) | |
download | django-cb13792938f2c887134eb6b5164d89f8d8f9f1bd.tar.gz |
Fixed #34437 -- Made values() resolving error mention selected annotations.
While the add_fields() call from set_values() does trigger validation it
does so after annotations are masked resulting in them being excluded
from the choices of valid options surfaced through a FieldError.
Diffstat (limited to 'tests/annotations')
-rw-r--r-- | tests/annotations/tests.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index e0cdbf1e0b..f1260b4192 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -33,6 +33,7 @@ from django.db.models.functions import ( Lower, Trim, ) +from django.db.models.sql.query import get_field_names_from_opts from django.test import TestCase, skipUnlessDBFeature from django.test.utils import register_lookup @@ -465,6 +466,16 @@ class NonAggregateAnnotationTestCase(TestCase): ) ) + def test_values_wrong_annotation(self): + expected_message = ( + "Cannot resolve keyword 'annotation_typo' into field. Choices are: %s" + ) + article_fields = ", ".join( + ["annotation"] + sorted(get_field_names_from_opts(Book._meta)) + ) + with self.assertRaisesMessage(FieldError, expected_message % article_fields): + Book.objects.annotate(annotation=Value(1)).values_list("annotation_typo") + def test_decimal_annotation(self): salary = Decimal(10) ** -Employee._meta.get_field("salary").decimal_places Employee.objects.create( |