Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit c77372cad034b06c1b7239ff6e1284c832f4a541 1 parent c8092b8
Jannis Leidel authored April 22, 2011
2  django/db/models/query.py
@@ -1385,7 +1385,7 @@ def __iter__(self):
1385 1385
             yield instance
1386 1386
 
1387 1387
     def __repr__(self):
1388  
-        return "<RawQuerySet: %r>" % (self.raw_query % self.params)
  1388
+        return "<RawQuerySet: %r>" % (self.raw_query % tuple(self.params))
1389 1389
 
1390 1390
     def __getitem__(self, k):
1391 1391
         return list(self)[k]
2  django/db/models/sql/query.py
@@ -74,7 +74,7 @@ def __iter__(self):
74 74
         return iter(result)
75 75
 
76 76
     def __repr__(self):
77  
-        return "<RawQuery: %r>" % (self.sql % self.params)
  77
+        return "<RawQuery: %r>" % (self.sql % tuple(self.params))
78 78
 
79 79
     def _execute_query(self):
80 80
         self.cursor = connections[self.using].cursor()
17  tests/regressiontests/queries/tests.py
@@ -1317,6 +1317,23 @@ def test_ticket3739(self):
1317 1317
         self.assertIsNot(q1, q1.all())
1318 1318
 
1319 1319
 
  1320
+class RawQueriesTests(TestCase):
  1321
+    def setUp(self):
  1322
+        n1 = Note.objects.create(note='n1', misc='foo', id=1)
  1323
+
  1324
+    def test_ticket14729(self):
  1325
+        # Test representation of raw query with one or few parameters passed as list
  1326
+        query = "SELECT * FROM queries_note WHERE note = %s"
  1327
+        params = ['n1']
  1328
+        qs = Note.objects.raw(query, params=params)
  1329
+        self.assertEqual(repr(qs), "<RawQuerySet: 'SELECT * FROM queries_note WHERE note = n1'>")
  1330
+
  1331
+        query = "SELECT * FROM queries_note WHERE note = %s and misc = %s"
  1332
+        params = ['n1', 'foo']
  1333
+        qs = Note.objects.raw(query, params=params)
  1334
+        self.assertEqual(repr(qs), "<RawQuerySet: 'SELECT * FROM queries_note WHERE note = n1 and misc = foo'>")
  1335
+
  1336
+
1320 1337
 class GeneratorExpressionTests(TestCase):
1321 1338
     def test_ticket10432(self):
1322 1339
         # Using an empty generator expression as the rvalue for an "__in"

0 notes on commit c77372c

Please sign in to comment.
Something went wrong with that request. Please try again.