mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[4.2.x] Fixed #34486 -- Fixed DatabaseOperations.compose_sql() crash with no existing database connection on PostgreSQL.
Regression in09ffc5c121. Backport of53aee470d5from main
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							cd464fbc3a
						
					
				
				
					commit
					090d5ccc6c
				
			| @@ -18,7 +18,8 @@ try: | ||||
|     TSTZRANGE_OID = types["tstzrange"].oid | ||||
|  | ||||
|     def mogrify(sql, params, connection): | ||||
|         return ClientCursor(connection.connection).mogrify(sql, params) | ||||
|         with connection.cursor() as cursor: | ||||
|             return ClientCursor(cursor.connection).mogrify(sql, params) | ||||
|  | ||||
|     # Adapters. | ||||
|     class BaseTzLoader(TimestamptzLoader): | ||||
|   | ||||
| @@ -37,3 +37,7 @@ Bugfixes | ||||
| * Fixed a regression in Django 4.2 where ``timesince`` and ``timeuntil`` | ||||
|   template filters returned incorrect results for a datetime with a non-UTC | ||||
|   timezone when a time difference is less than 1 day (:ticket:`34483`). | ||||
|  | ||||
| * Fixed a regression in Django 4.2 that caused a crash of | ||||
|   :class:`~django.contrib.postgres.search.SearchHeadline` function with | ||||
|   ``psycopg`` 3 (:ticket:`34486`). | ||||
|   | ||||
| @@ -420,3 +420,13 @@ class Tests(TestCase): | ||||
|         with self.assertRaisesMessage(NotSupportedError, msg): | ||||
|             connection.check_database_version_supported() | ||||
|         self.assertTrue(mocked_get_database_version.called) | ||||
|  | ||||
|     def test_compose_sql_when_no_connection(self): | ||||
|         new_connection = connection.copy() | ||||
|         try: | ||||
|             self.assertEqual( | ||||
|                 new_connection.ops.compose_sql("SELECT %s", ["test"]), | ||||
|                 "SELECT 'test'", | ||||
|             ) | ||||
|         finally: | ||||
|             new_connection.close() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user