#26185 closed Bug (wontfix)
values_list throws interesting error when ordering by an extra column
Reported by: | Sven R. Kunze | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
MyModel.objects.extra(select={'my_column': 'adas'}).order_by('my_column').values_list('id', flat=True) ProgrammingError: column "adas" does not exist LINE 1: ...arch3_beleg"."id" FROM "modarch3_beleg" ORDER BY (adas) ASC ...
There's already a similar ticket (but it's closed as fixed) https://code.djangoproject.com/ticket/14930
Change History (5)
comment:1 by , 9 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 9 years ago
How are we supposed to construct such queries then?
As usual the given example is minimal: so the actual working flow goes like this:
# 1 create complex queryset ... more code # 2 add extra select and where ... more code # 3 add order (maybe referring to the extra column) ... more code # 4 wrap paginator around queryset ... more code # 5 create values_list of paged queryset ... more code # 6 evaluate <<<< crash
comment:3 by , 9 years ago
If you have trouble using the expressions API, please ask using our support channels: TicketClosingReasons/UseSupportChannels.
comment:4 by , 9 years ago
I was able to rewrite the extra statement using a combination of Expression (for select) and extra (for where). So, I think we are set for now.
If you really consider deprecating extra, there would need to be a facility to add custom where clauses.
As noted in the docs, we aren't fixed bugs that involved
QuerySet.extra()
.