Fixed #14729 -- RawQuerySet.__repr__ fails when params passed as list. Thanks, intgr for ticket and accuser for patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16088 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-04-22 18:17:26 +00:00
parent c8092b840b
commit c77372cad0
3 changed files with 19 additions and 2 deletions

View File

@ -1385,7 +1385,7 @@ class RawQuerySet(object):
yield instance
def __repr__(self):
return "<RawQuerySet: %r>" % (self.raw_query % self.params)
return "<RawQuerySet: %r>" % (self.raw_query % tuple(self.params))
def __getitem__(self, k):
return list(self)[k]

View File

@ -74,7 +74,7 @@ class RawQuery(object):
return iter(result)
def __repr__(self):
return "<RawQuery: %r>" % (self.sql % self.params)
return "<RawQuery: %r>" % (self.sql % tuple(self.params))
def _execute_query(self):
self.cursor = connections[self.using].cursor()

View File

@ -1317,6 +1317,23 @@ class Queries6Tests(TestCase):
self.assertIsNot(q1, q1.all())
class RawQueriesTests(TestCase):
def setUp(self):
n1 = Note.objects.create(note='n1', misc='foo', id=1)
def test_ticket14729(self):
# Test representation of raw query with one or few parameters passed as list
query = "SELECT * FROM queries_note WHERE note = %s"
params = ['n1']
qs = Note.objects.raw(query, params=params)
self.assertEqual(repr(qs), "<RawQuerySet: 'SELECT * FROM queries_note WHERE note = n1'>")
query = "SELECT * FROM queries_note WHERE note = %s and misc = %s"
params = ['n1', 'foo']
qs = Note.objects.raw(query, params=params)
self.assertEqual(repr(qs), "<RawQuerySet: 'SELECT * FROM queries_note WHERE note = n1 and misc = foo'>")
class GeneratorExpressionTests(TestCase):
def test_ticket10432(self):
# Using an empty generator expression as the rvalue for an "__in"