Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #18592 -- Prevented crash when accessing MySQL _last_executed

Thanks reames at asymmetricventures.com for the report.
  • Loading branch information...
commit 59b0c48ce27951048146358739baf08056c5e821 1 parent 7fbab3e
@claudep claudep authored
Showing with 12 additions and 1 deletion.
  1. +1 −1  django/db/backends/mysql/base.py
  2. +11 −0 tests/backends/tests.py
View
2  django/db/backends/mysql/base.py
@@ -284,7 +284,7 @@ def last_executed_query(self, cursor, sql, params):
# With MySQLdb, cursor objects have an (undocumented) "_last_executed"
# attribute where the exact query sent to the database is saved.
# See MySQLdb/cursors.py in the source distribution.
- return force_text(cursor._last_executed, errors='replace')
+ return force_text(getattr(cursor, '_last_executed', None), errors='replace')
def no_limit_value(self):
# 2**64 - 1, as recommended by the MySQL documentation
View
11 tests/backends/tests.py
@@ -164,6 +164,17 @@ def test_django_date_extract(self):
@override_settings(DEBUG=True)
class LastExecutedQueryTest(TestCase):
+ def test_last_executed_query(self):
+ """
+ last_executed_query should not raise an exception even if no previous
+ query has been run.
+ """
+ cursor = connection.cursor()
+ try:
+ connection.ops.last_executed_query(cursor, '', ())
+ except Exception:
+ self.fail("'last_executed_query' should not raise an exception.")
+
def test_debug_sql(self):
list(models.Reporter.objects.filter(first_name="test"))
sql = connection.queries[-1]['sql'].lower()
Please sign in to comment.
Something went wrong with that request. Please try again.