mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[3.2.x] Fixed #32450 -- Fixed crash when ANDing/ORing an empty Q() with not pickleable Q().
Regression inbb0b6e5263. Backport of466920f6d7from master
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							6897da6096
						
					
				
				
					commit
					0e2979e95d
				
			| @@ -5,7 +5,6 @@ Factored out from django.db.models.query to avoid making the main module very | ||||
| large and/or so that they can be used by other modules without getting into | ||||
| circular import difficulties. | ||||
| """ | ||||
| import copy | ||||
| import functools | ||||
| import inspect | ||||
| import warnings | ||||
| @@ -74,10 +73,12 @@ class Q(tree.Node): | ||||
|  | ||||
|         # If the other Q() is empty, ignore it and just use `self`. | ||||
|         if not other: | ||||
|             return copy.deepcopy(self) | ||||
|             _, args, kwargs = self.deconstruct() | ||||
|             return type(self)(*args, **kwargs) | ||||
|         # Or if this Q is empty, ignore it and just use `other`. | ||||
|         elif not self: | ||||
|             return copy.deepcopy(other) | ||||
|             _, args, kwargs = other.deconstruct() | ||||
|             return type(other)(*args, **kwargs) | ||||
|  | ||||
|         obj = type(self)() | ||||
|         obj.connector = conn | ||||
|   | ||||
| @@ -8,6 +8,10 @@ class QTests(SimpleTestCase): | ||||
|         self.assertEqual(q & Q(), q) | ||||
|         self.assertEqual(Q() & q, q) | ||||
|  | ||||
|         q = Q(x__in={}.keys()) | ||||
|         self.assertEqual(q & Q(), q) | ||||
|         self.assertEqual(Q() & q, q) | ||||
|  | ||||
|     def test_combine_and_both_empty(self): | ||||
|         self.assertEqual(Q() & Q(), Q()) | ||||
|  | ||||
| @@ -16,6 +20,10 @@ class QTests(SimpleTestCase): | ||||
|         self.assertEqual(q | Q(), q) | ||||
|         self.assertEqual(Q() | q, q) | ||||
|  | ||||
|         q = Q(x__in={}.keys()) | ||||
|         self.assertEqual(q | Q(), q) | ||||
|         self.assertEqual(Q() | q, q) | ||||
|  | ||||
|     def test_combine_or_both_empty(self): | ||||
|         self.assertEqual(Q() | Q(), Q()) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user