#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 (asking as noted in the docs)?
As usual the given example is minimal: so the actual working flow goes like this:
# create complex queryset ... more code # add extra column ... more code # add order (maybe referring to extra column) ... more code # create values_list queryset ... more code # 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()
.