#29610: Crash in sqlite3 last_executed_query when using printf() formatting
-------------------------------------+-------------------------------------
               Reporter:  Matthias   |          Owner:  nobody
  Kestenholz                         |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.0
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Here's a minimal testcase which shows the problem:

 {{{
 diff --git a/tests/backends/sqlite/tests.py
 b/tests/backends/sqlite/tests.py
 index c82ed1667d..297b658810 100644
 --- a/tests/backends/sqlite/tests.py
 +++ b/tests/backends/sqlite/tests.py
 @@ -128,6 +128,12 @@ class LastExecutedQueryTest(TestCase):
              # This should not raise an exception.
              cursor.db.ops.last_executed_query(cursor.cursor, sql, params)

 +    def test_printf(self):
 +        with connection.cursor() as cursor:
 +            sql = "SELECT printf(\"%x\", 10), %s"
 +            params = ["hello"]
 +            cursor.db.ops.last_executed_query(cursor.cursor, sql, params)
 +

  @unittest.skipUnless(connection.vendor == 'sqlite', 'SQLite tests')
  class EscapingChecks(TestCase):
 }}}

 Here's the exception I got:

 {{{
 ERROR: test_printf (backends.sqlite.tests.LastExecutedQueryTest)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/home/matthias/Projects/django/tests/backends/sqlite/tests.py",
 line 135, in test_printf
     cursor.db.ops.last_executed_query(cursor.cursor, sql, params)
   File
 "/home/matthias/Projects/django/django/db/backends/sqlite3/operations.py",
 line 147, in last_executed_query
     return sql % params
 TypeError: %x format: an integer is required, not str
 }}}
 A real world example of using printf() can be found here:
 https://github.com/matthiask/django-tree-
 
queries/blob/7eb6996203ad128dcef8fc88b29afa87dc2a4164/tree_queries/compiler.py#L69

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29610>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.ff73b70043acd5d599c7093784d60bec%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to