Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 jezdez authored
2  django/db/models/query.py
View
@@ -1385,7 +1385,7 @@ def __iter__(self):
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]
2  django/db/models/sql/query.py
View
@@ -74,7 +74,7 @@ def __iter__(self):
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()
17 tests/regressiontests/queries/tests.py
View
@@ -1317,6 +1317,23 @@ def test_ticket3739(self):
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"
Please sign in to comment.
Something went wrong with that request. Please try again.