﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29610	Crash in sqlite3 last_executed_query when using printf() formatting	Matthias Kestenholz	nobody	"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"	Uncategorized	closed	Database layer (models, ORM)	2.0	Normal	invalid			Unreviewed	0	0	0	0	0	0
