mirror of
				https://github.com/django/django.git
				synced 2025-10-26 07:06:08 +00:00 
			
		
		
		
	Refs #26071 -- Added test for __in lookup in a Case expression.
Forwardport of 5b3c66d8b6 from stable/1.8.x
			
			
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							d45cfefbad
						
					
				
				
					commit
					cca151d196
				
			| @@ -23,3 +23,6 @@ Bugfixes | |||||||
|   ``db_index=True`` or ``unique=True`` to a ``CharField`` or ``TextField`` that |   ``db_index=True`` or ``unique=True`` to a ``CharField`` or ``TextField`` that | ||||||
|   already had the other specified, or when removing one of them from a field |   already had the other specified, or when removing one of them from a field | ||||||
|   that had both (:ticket:`26034`). |   that had both (:ticket:`26034`). | ||||||
|  |  | ||||||
|  | * Fixed a crash when using an ``__in`` lookup inside a ``Case`` expression | ||||||
|  |   (:ticket:`26071`). | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ from uuid import UUID | |||||||
|  |  | ||||||
| from django.core.exceptions import FieldError | from django.core.exceptions import FieldError | ||||||
| from django.db import connection, models | from django.db import connection, models | ||||||
| from django.db.models import F, Q, Max, Min, Value | from django.db.models import F, Q, Max, Min, Sum, Value | ||||||
| from django.db.models.expressions import Case, When | from django.db.models.expressions import Case, When | ||||||
| from django.test import TestCase | from django.test import TestCase | ||||||
| from django.utils import six | from django.utils import six | ||||||
| @@ -119,6 +119,17 @@ class CaseExpressionTests(TestCase): | |||||||
|             transform=attrgetter('integer', 'join_test') |             transform=attrgetter('integer', 'join_test') | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |     def test_annotate_with_in_clause(self): | ||||||
|  |         fk_rels = FKCaseTestModel.objects.filter(integer__in=[5]) | ||||||
|  |         self.assertQuerysetEqual( | ||||||
|  |             CaseTestModel.objects.only('pk', 'integer').annotate(in_test=Sum(Case( | ||||||
|  |                 When(fk_rel__in=fk_rels, then=F('fk_rel__integer')), | ||||||
|  |                 default=Value(0), | ||||||
|  |             ))).order_by('pk'), | ||||||
|  |             [(1, 0), (2, 0), (3, 0), (2, 0), (3, 0), (3, 0), (4, 5)], | ||||||
|  |             transform=attrgetter('integer', 'in_test') | ||||||
|  |         ) | ||||||
|  |  | ||||||
|     def test_annotate_with_join_in_condition(self): |     def test_annotate_with_join_in_condition(self): | ||||||
|         self.assertQuerysetEqual( |         self.assertQuerysetEqual( | ||||||
|             CaseTestModel.objects.annotate(join_test=Case( |             CaseTestModel.objects.annotate(join_test=Case( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user