Re: [Django] #36352: values() raises a FieldError when multiple values() of annotated values are chained

19 views
Skip to first unread message

Django

unread,
Apr 29, 2025, 1:10:01 AM4/29/25
to django-...@googlegroups.com
#36352: values() raises a FieldError when multiple values() of annotated values are
chained
-------------------------------------+-------------------------------------
Reporter: Joseph Yu | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: .values, distinct | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

It looks like we could error out with a more appropriate message but we've
made some significant changes in since 4.2 to prevent obscuring existing
field references with annotations.

In other words I would expect calls of the form
`Mapping.objects.annotate(foo=F('foo__name'))` and
`Mapping.objects.annotate(foo_id=F('foo_id'))` to always be problematic to
some extent even when values is used as they turn follow up references to
such annotations ambiguous.

For example, what should
`annotate(foo=F('foo__name')).filter(foo__name="Bar")` resolve to or
surface as error?
--
Ticket URL: <https://code.djangoproject.com/ticket/36352#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 29, 2025, 5:07:54 AM4/29/25
to django-...@googlegroups.com
#36352: values() raises a FieldError when multiple values() of annotated values are
chained
-------------------------------------+-------------------------------------
Reporter: Joseph Yu | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: .values, distinct | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* type: Bug => Cleanup/optimization

Comment:

Good point, happy to have a more helpful error message
--
Ticket URL: <https://code.djangoproject.com/ticket/36352#comment:11>

Django

unread,
May 17, 2025, 11:50:49 PM5/17/25
to django-...@googlegroups.com
#36352: values() raises a FieldError when multiple values() of annotated values are
chained
-------------------------------------+-------------------------------------
Reporter: Joseph Yu | Owner:
Type: | JaeHyuckSa
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: .values, distinct | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JaeHyuckSa):

* has_patch: 0 => 1
* owner: (none) => JaeHyuckSa
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36352#comment:12>

Django

unread,
Jun 2, 2025, 8:40:54 AM6/2/25
to django-...@googlegroups.com
#36352: values() raises a FieldError when multiple values() of annotated values are
chained
-------------------------------------+-------------------------------------
Reporter: Joseph Yu | Owner:
Type: | JaeHyuckSa
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: .values, distinct | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by ontowhee):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36352#comment:13>

Django

unread,
Jan 15, 2026, 10:56:09 AM (9 days ago) Jan 15
to django-...@googlegroups.com
#36352: values() raises a FieldError when multiple values() of annotated values are
chained
-------------------------------------+-------------------------------------
Reporter: Joseph Yu | Owner:
Type: | JaeHyuckSa
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: .values, distinct | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by JaeHyuckSa):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36352#comment:14>

Django

unread,
Jan 16, 2026, 9:12:13 AM (8 days ago) Jan 16
to django-...@googlegroups.com
#36352: values() raises a FieldError when multiple values() of annotated values are
chained
-------------------------------------+-------------------------------------
Reporter: Joseph Yu | Owner:
Type: | JaeHyuckSa
Cleanup/optimization | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: .values, distinct | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36352#comment:15>

Django

unread,
Jan 16, 2026, 10:28:25 AM (8 days ago) Jan 16
to django-...@googlegroups.com
#36352: values() raises a FieldError when multiple values() of annotated values are
chained
-------------------------------------+-------------------------------------
Reporter: Joseph Yu | Owner:
Type: | JaeHyuckSa
Cleanup/optimization | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: .values, distinct | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"0239e86f387127dace7273208c300b33a065e021" 0239e86f]:
{{{#!CommitTicketReference repository=""
revision="0239e86f387127dace7273208c300b33a065e021"
Fixed #36352 -- Improved error message for fields excluded by prior
values()/values_list() calls.

Signed-off-by: JaeHyuck Sa <wogur...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36352#comment:16>
Reply all
Reply to author
Forward
0 new messages