﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6940	Bug in count() when string formats in select	m.gajda@…	nobody	"Hi!

I have found a bug in Django ORM. This very rare situation, it occured in my application code. I have created complex query using extra() function on query set. This query contains some formatting strings in ""select"" clause, which will be filled up using ""params"" clause.

In this case, query set's count() function fails. The reason is in file django/db/models/query.py, in count() method. This method invokes query, but it completely omits the ""SELECT"" part of generated query. However - all formatting parameters are still passed to the query executing function. Below the example:

{{{
> from django.contrib.auth.models import User

> User.objects.filter( pk = 1 ).extra( select = { ""foo"" : ""%s"" } , params = ( ""bar"" , ) ).count()
...
<type 'exceptions.TypeError'>: not all arguments converted during string formatting

}}}

I've have created simple patch fixing this bug. It just counts the number of string formats in ""select"" clause and removed respecting parameters from ""params"" clause.

I hope, that you will fix the bug soon.

Best regards,
-- 
Marcin Gajda"		closed	Database layer (models, ORM)	dev		duplicate	bug count orm string format qs-rf		Accepted	1	0	0	0	0	0
