Ticket #14729: rev14757_raw_query_repr.diff

File rev14757_raw_query_repr.diff, 2.1 KB (added by Alexey Smolsky, 14 years ago)

Tests moved in other place

  • django/db/models/sql/query.py

     
    8080        return iter(result)
    8181
    8282    def __repr__(self):
    83         return "<RawQuery: %r>" % (self.sql % self.params)
     83        return "<RawQuery: %r>" % (self.sql % tuple(self.params))
    8484
    8585    def _execute_query(self):
    8686        self.cursor = connections[self.using].cursor()
  • django/db/models/query.py

     
    13631363            yield instance
    13641364
    13651365    def __repr__(self):
    1366         return "<RawQuerySet: %r>" % (self.raw_query % self.params)
     1366        return "<RawQuerySet: %r>" % (self.raw_query % tuple(self.params))
    13671367
    13681368    def __getitem__(self, k):
    13691369        return list(self)[k]
  • tests/regressiontests/queries/tests.py

     
    13051305        self.assertIsNot(q1, q1.all())
    13061306
    13071307
     1308class RawQueriesTests(TestCase):
     1309    def setUp(self):
     1310        n1 = Note.objects.create(note='n1', misc='foo', id=1)
     1311
     1312    def test_ticket14729(self):
     1313        # Test representation of raw query with one or few parameters passed as list
     1314        query = "SELECT * FROM queries_note WHERE note = %s"
     1315        params = ['n1']
     1316        qs = Note.objects.raw(query, params=params)
     1317        self.assertEqual(repr(qs), "<RawQuerySet: 'SELECT * FROM queries_note WHERE note = n1'>")
     1318
     1319        query = "SELECT * FROM queries_note WHERE note = %s and misc = %s"
     1320        params = ['n1', 'foo']
     1321        qs = Note.objects.raw(query, params=params)
     1322        self.assertEqual(repr(qs), "<RawQuerySet: 'SELECT * FROM queries_note WHERE note = n1 and misc = foo'>")
     1323
     1324
    13081325class GeneratorExpressionTests(TestCase):
    13091326    def test_ticket10432(self):
    13101327        # Using an empty generator expression as the rvalue for an "__in"
Back to Top