Opened 5 years ago

Closed 5 years ago

Last modified 5 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 Changed 5 years ago by Tim Graham

Resolution: wontfix
Status: newclosed

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

comment:2 Changed 5 years ago by Sven R. Kunze

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
Last edited 5 years ago by Sven R. Kunze (previous) (diff)

comment:3 Changed 5 years ago by Tim Graham

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

comment:4 Changed 5 years ago by Sven R. Kunze

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 Changed 5 years ago by Sven R. Kunze

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

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