Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#1685 closed defect (fixed)

[patch] order_by breaks for column in a custom SELECT

Reported by: feiyu.xie@… Owned by: adrian
Component: Database layer (models, ORM) Version: magic-removal
Severity: normal Keywords: order_by, extra select, custom select
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Here is an example:

        select = {
                'votes': 'SELECT COUNT(*) FROM faxian_vote WHERE',
        order_by = '-votes'
        sl = Story.objects.extra(select=select,).filter(promotion_ts__isnull=False,).order_by(order_by)[:10]

The problematic line is in django\models\, line 430:

        if "." not in col_name and col_name not in [k[0] for k in (self._select or ())]:

k[0] will be the first letter of the key name in self._select, in this case, 'v'

So it should be changed to:

        if "." not in col_name and col_name not in [k for k in (self._select or ())]:

Attachments (1) (813 bytes) - added by feiyu.xie@… 10 years ago.

Download all attachments as: .zip

Change History (3)

Changed 10 years ago by feiyu.xie@…

comment:1 Changed 10 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [2803]) magic-removal: Fixed #1685 -- order_by no longer breaks when using a custom 'select'. Thanks, feiyu.xie

comment:2 Changed 9 years ago by adrian

  • milestone Version 0.92 deleted

Milestone Version 0.92 deleted

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