mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.6.x] Fixed #18592 -- Prevented crash when accessing MySQL _last_executed
Thanks reames at asymmetricventures.com for the report.
Backport of 59b0c48ce from master.
			
			
This commit is contained in:
		| @@ -284,7 +284,7 @@ class DatabaseOperations(BaseDatabaseOperations): | |||||||
|         # With MySQLdb, cursor objects have an (undocumented) "_last_executed" |         # With MySQLdb, cursor objects have an (undocumented) "_last_executed" | ||||||
|         # attribute where the exact query sent to the database is saved. |         # attribute where the exact query sent to the database is saved. | ||||||
|         # See MySQLdb/cursors.py in the source distribution. |         # 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): |     def no_limit_value(self): | ||||||
|         # 2**64 - 1, as recommended by the MySQL documentation |         # 2**64 - 1, as recommended by the MySQL documentation | ||||||
|   | |||||||
| @@ -164,6 +164,17 @@ class DateQuotingTest(TestCase): | |||||||
| @override_settings(DEBUG=True) | @override_settings(DEBUG=True) | ||||||
| class LastExecutedQueryTest(TestCase): | 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): |     def test_debug_sql(self): | ||||||
|         list(models.Reporter.objects.filter(first_name="test")) |         list(models.Reporter.objects.filter(first_name="test")) | ||||||
|         sql = connection.queries[-1]['sql'].lower() |         sql = connection.queries[-1]['sql'].lower() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user