mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #32182 -- Fixed crash of JSONField nested key transforms with subquery annotations on PostgreSQL.
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							dbb4a86fa7
						
					
				
				
					commit
					0773837e15
				
			| @@ -302,7 +302,8 @@ class KeyTransform(Transform): | ||||
|     def as_postgresql(self, compiler, connection): | ||||
|         lhs, params, key_transforms = self.preprocess_lhs(compiler, connection) | ||||
|         if len(key_transforms) > 1: | ||||
|             return '(%s %s %%s)' % (lhs, self.postgres_nested_operator), params + [key_transforms] | ||||
|             sql = '(%s %s %%s)' % (lhs, self.postgres_nested_operator) | ||||
|             return sql, tuple(params) + (key_transforms,) | ||||
|         try: | ||||
|             lookup = int(self.key_name) | ||||
|         except ValueError: | ||||
|   | ||||
| @@ -14,3 +14,6 @@ Bugfixes | ||||
|  | ||||
| * Fixed passing extra HTTP headers to ``AsyncRequestFactory`` request methods | ||||
|   (:ticket:`32159`). | ||||
|  | ||||
| * Fixed crash of key transforms for :class:`~django.db.models.JSONField` on | ||||
|   PostgreSQL when using on a ``Subquery()`` annotation (:ticket:`32182`). | ||||
|   | ||||
| @@ -408,6 +408,18 @@ class TestQuerying(TestCase): | ||||
|             [self.objs[4]], | ||||
|         ) | ||||
|  | ||||
|     def test_nested_key_transform_on_subquery(self): | ||||
|         self.assertSequenceEqual( | ||||
|             NullableJSONModel.objects.filter(value__d__0__isnull=False).annotate( | ||||
|                 subquery_value=Subquery( | ||||
|                     NullableJSONModel.objects.filter(pk=OuterRef('pk')).values('value') | ||||
|                 ), | ||||
|                 key=KeyTransform('d', 'subquery_value'), | ||||
|                 chain=KeyTransform('f', KeyTransform('1', 'key')), | ||||
|             ).filter(chain='g'), | ||||
|             [self.objs[4]], | ||||
|         ) | ||||
|  | ||||
|     def test_expression_wrapper_key_transform(self): | ||||
|         self.assertSequenceEqual( | ||||
|             NullableJSONModel.objects.annotate( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user