mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	[3.0.x] Fixed #30986 -- Fixed queryset crash when filtering against boolean RawSQL expressions on Oracle.
Backport of 8685e764ef from master
			
			
This commit is contained in:
		| @@ -6,7 +6,7 @@ from functools import lru_cache | |||||||
| from django.conf import settings | from django.conf import settings | ||||||
| from django.db.backends.base.operations import BaseDatabaseOperations | from django.db.backends.base.operations import BaseDatabaseOperations | ||||||
| from django.db.backends.utils import strip_quotes, truncate_name | from django.db.backends.utils import strip_quotes, truncate_name | ||||||
| from django.db.models.expressions import Exists, ExpressionWrapper | from django.db.models.expressions import Exists, ExpressionWrapper, RawSQL | ||||||
| from django.db.models.query_utils import Q | from django.db.models.query_utils import Q | ||||||
| from django.db.utils import DatabaseError | from django.db.utils import DatabaseError | ||||||
| from django.utils import timezone | from django.utils import timezone | ||||||
| @@ -625,4 +625,6 @@ END; | |||||||
|             return True |             return True | ||||||
|         if isinstance(expression, ExpressionWrapper) and isinstance(expression.expression, Q): |         if isinstance(expression, ExpressionWrapper) and isinstance(expression.expression, Q): | ||||||
|             return True |             return True | ||||||
|  |         if isinstance(expression, RawSQL) and expression.conditional: | ||||||
|  |             return True | ||||||
|         return False |         return False | ||||||
|   | |||||||
| @@ -91,6 +91,14 @@ class BasicExpressionsTests(TestCase): | |||||||
|             2, |             2, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |     def test_filtering_on_rawsql_that_is_boolean(self): | ||||||
|  |         self.assertEqual( | ||||||
|  |             Company.objects.filter( | ||||||
|  |                 RawSQL('num_employees > %s', (3,), output_field=models.BooleanField()), | ||||||
|  |             ).count(), | ||||||
|  |             2, | ||||||
|  |         ) | ||||||
|  |  | ||||||
|     def test_filter_inter_attribute(self): |     def test_filter_inter_attribute(self): | ||||||
|         # We can filter on attribute relationships on same model obj, e.g. |         # We can filter on attribute relationships on same model obj, e.g. | ||||||
|         # find companies where the number of employees is greater |         # find companies where the number of employees is greater | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user