﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37480	FieldError for annotation excluded by previous values() call incorrectly refers to unpromoted alias	Jacob Walls	Django Sprints	"#36352 improved the `FieldError` message text when an annotation alias is requested via `values()` after being excluded by an earlier `values()` call.

However, it doesn't handle the case where the prior values call excludes ''all'' annotations, as in the last example below:

[https://dryorm.xterm.info/bugfield-error-message DryORM fiddle]
{{{#!py
from django.db import models

class Person(models.Model):
    name = models.CharField(max_length=100)


def run():
    # qs = (
    #     Person.objects.annotate(a=models.Value(42), b=models.Value(43))
    #     .values(""a"")
    #     # CORRECT:
    #     # FieldError: Cannot select the 'b' alias. It was excluded by a
    #     # previous values() or values_list() call. Include 'b' in that
    #     # call to select it.
    #     .values(""b"")
    # )
    
    qs = (
        Person.objects.annotate(a=models.Value(42), b=models.Value(43))
        .values(""pk"")
        # INCORRECT:
        # FieldError: Cannot select the 'b' alias. Use annotate() to promote it.
        .values(""b"")
    )

}}}

I think we could check the contents of `self.annotations` (the annotations that have been registered) and `self.annotation_select` (the annotations that have been selected by a prior `values()` call) instead of only checking whether one or the other is empty."	Cleanup/optimization	assigned	Database layer (models, ORM)	6.1	Low				Accepted	0	0	0	0	0	0
