From c77372cad034b06c1b7239ff6e1284c832f4a541 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 22 Apr 2011 18:17:26 +0000 Subject: [PATCH] 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 --- django/db/models/query.py | 2 +- django/db/models/sql/query.py | 2 +- tests/regressiontests/queries/tests.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 09d960b3ec..9c3aeaa8d3 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1385,7 +1385,7 @@ class RawQuerySet(object): yield instance def __repr__(self): - return "" % (self.raw_query % self.params) + return "" % (self.raw_query % tuple(self.params)) def __getitem__(self, k): return list(self)[k] diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index f41272cf0f..c29673ecdd 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -74,7 +74,7 @@ class RawQuery(object): return iter(result) def __repr__(self): - return "" % (self.sql % self.params) + return "" % (self.sql % tuple(self.params)) def _execute_query(self): self.cursor = connections[self.using].cursor() diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py index c87ecd32df..31856ba3a6 100644 --- a/tests/regressiontests/queries/tests.py +++ b/tests/regressiontests/queries/tests.py @@ -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), "") + + 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), "") + + class GeneratorExpressionTests(TestCase): def test_ticket10432(self): # Using an empty generator expression as the rvalue for an "__in"