mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.8.x] Fixed #24318 -- Set the transaction isolation level with psycopg >= 2.4.2.
Backport of 76356d96 from master
			
			
This commit is contained in:
		| @@ -238,6 +238,34 @@ class PostgreSQLTests(TestCase): | ||||
|         finally: | ||||
|             new_connection.close() | ||||
|  | ||||
|     def test_connect_isolation_level(self): | ||||
|         """ | ||||
|         Regression test for #18130 and #24318. | ||||
|         """ | ||||
|         from psycopg2.extensions import ( | ||||
|             ISOLATION_LEVEL_READ_COMMITTED as read_committed, | ||||
|             ISOLATION_LEVEL_SERIALIZABLE as serializable, | ||||
|         ) | ||||
|  | ||||
|         # Since this is a django.test.TestCase, a transaction is in progress | ||||
|         # and the isolation level isn't reported as 0. This test assumes that | ||||
|         # PostgreSQL is configured with the default isolation level. | ||||
|  | ||||
|         # Check the level on the psycopg2 connection, not the Django wrapper. | ||||
|         self.assertEqual(connection.connection.isolation_level, read_committed) | ||||
|  | ||||
|         databases = copy.deepcopy(settings.DATABASES) | ||||
|         databases[DEFAULT_DB_ALIAS]['OPTIONS']['isolation_level'] = serializable | ||||
|         new_connections = ConnectionHandler(databases) | ||||
|         new_connection = new_connections[DEFAULT_DB_ALIAS] | ||||
|         try: | ||||
|             # Start a transaction so the isolation level isn't reported as 0. | ||||
|             new_connection.set_autocommit(False) | ||||
|             # Check the level on the psycopg2 connection, not the Django wrapper. | ||||
|             self.assertEqual(new_connection.connection.isolation_level, serializable) | ||||
|         finally: | ||||
|             new_connection.close() | ||||
|  | ||||
|     def _select(self, val): | ||||
|         with connection.cursor() as cursor: | ||||
|             cursor.execute("SELECT %s", (val,)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user