#1685 closed defect (fixed)
[patch] order_by breaks for column in a custom SELECT
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
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: | no | UI/UX: | no |
Description
Here is an example:
select = { 'votes': 'SELECT COUNT(*) FROM faxian_vote WHERE story_id=faxian_story.id', } 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\query.py, 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)
Change History (3)
by , 19 years ago
Attachment: | query.py.patch added |
---|
comment:1 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
(In [2803]) magic-removal: Fixed #1685 -- order_by no longer breaks when using a custom 'select'. Thanks, feiyu.xie