mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #30011 -- Fixed queries that reuse filtered aggregates.
Thanks Taqi Abbas and Raphael Kimmig for the report.
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							88619e6129
						
					
				
				
					commit
					53269bcaaf
				
			| @@ -27,7 +27,7 @@ class Aggregate(Func): | ||||
|     def get_source_expressions(self): | ||||
|         source_expressions = super().get_source_expressions() | ||||
|         if self.filter: | ||||
|             source_expressions += [self.filter] | ||||
|             return source_expressions + [self.filter] | ||||
|         return source_expressions | ||||
|  | ||||
|     def set_source_expressions(self, exprs): | ||||
|   | ||||
| @@ -79,3 +79,11 @@ class FilteredAggregateTests(TestCase): | ||||
|         msg = 'Star cannot be used with filter. Please specify a field.' | ||||
|         with self.assertRaisesMessage(ValueError, msg): | ||||
|             Count('*', filter=Q(age=40)) | ||||
|  | ||||
|     def test_filtered_reused_subquery(self): | ||||
|         qs = Author.objects.annotate( | ||||
|             older_friends_count=Count('friends', filter=Q(friends__age__gt=F('age'))), | ||||
|         ).filter( | ||||
|             older_friends_count__gte=2, | ||||
|         ) | ||||
|         self.assertEqual(qs.get(pk__in=qs.values('pk')), self.a1) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user