Django

Code

Ticket #1685 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] order_by breaks for column in a custom SELECT

Reported by: feiyu.xie@gmail.com Assigned to: adrian
Milestone: Component: Database wrapper
Version: magic-removal Keywords: order_by, extra select,custom select
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

query.py.patch (0.8 kB) - added by feiyu.xie@gmail.com on 04/25/06 16:24:45.

Change History

04/25/06 16:24:45 changed by feiyu.xie@gmail.com

  • attachment query.py.patch added.

05/01/06 18:27:46 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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

10/24/06 15:17:23 changed by adrian

  • milestone deleted.

Milestone Version 0.92 deleted


Add/Change #1685 ([patch] order_by breaks for column in a custom SELECT)




Change Properties
Action