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

17 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,
10:56 AM (3 hours ago) 10:56 AM
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>
Reply all
Reply to author
Forward
0 new messages