mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #19954 -- Fixed MySQL _last_executed decoding
Queries can contain binary data undecodable with utf-8. In this case, using the 'replace' errors mode when decoding seems like an acceptable representation of the query. Thanks Marcel Ryser for the report.
This commit is contained in:
parent
ef348b5298
commit
86b1c31689
3 changed files with 8 additions and 7 deletions
|
@ -157,18 +157,18 @@ class DateQuotingTest(TestCase):
|
|||
class LastExecutedQueryTest(TestCase):
|
||||
|
||||
def test_debug_sql(self):
|
||||
list(models.Tag.objects.filter(name="test"))
|
||||
list(models.Reporter.objects.filter(first_name="test"))
|
||||
sql = connection.queries[-1]['sql'].lower()
|
||||
self.assertIn("select", sql)
|
||||
self.assertIn(models.Tag._meta.db_table, sql)
|
||||
self.assertIn(models.Reporter._meta.db_table, sql)
|
||||
|
||||
def test_query_encoding(self):
|
||||
"""
|
||||
Test that last_executed_query() returns an Unicode string
|
||||
"""
|
||||
tags = models.Tag.objects.extra(select={'föö': 1})
|
||||
sql, params = tags.query.sql_with_params()
|
||||
cursor = tags.query.get_compiler('default').execute_sql(None)
|
||||
persons = models.Reporter.objects.filter(raw_data=b'\x00\x46 \xFE').extra(select={'föö': 1})
|
||||
sql, params = persons.query.sql_with_params()
|
||||
cursor = persons.query.get_compiler('default').execute_sql(None)
|
||||
last_sql = cursor.db.ops.last_executed_query(cursor, sql, params)
|
||||
self.assertTrue(isinstance(last_sql, six.text_type))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue