Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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 Tim Graham, 8 years ago

Resolution: wontfix
Status: newclosed

As noted in the docs, we aren't fixed bugs that involved QuerySet.extra().

comment:2 by Sven R. Kunze, 8 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 create values_list queryset
... more code
# 5 evaluate <<<< crash
Version 4, edited 8 years ago by Sven R. Kunze (previous) (next) (diff)

comment:3 by Tim Graham, 8 years ago

If you have trouble using the expressions API, please ask using our support channels: TicketClosingReasons/UseSupportChannels.

comment:4 by Sven R. Kunze, 8 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.

comment:5 by Sven R. Kunze, 8 years ago

@timgraham thanks for pointing me at the docs. :)

Note: See TracTickets for help on using tickets.
Back to Top