summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2019-11-15 10:25:39 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-11-18 09:16:21 +0100
commitb6be0699b9e2f39c1cbd20e36c58d6c3dc70a1f0 (patch)
tree9771f9d596b2a279cc322bedaa4a81555551a120
parentfa6076daf460df2c2c5ff9f62862f050bc4427f4 (diff)
[3.0.x] Fixed #30986 -- Fixed queryset crash when filtering against boolean RawSQL expressions on Oracle.
Backport of 8685e764efd2957085762d9249e07794d9a58dcb from master
-rw-r--r--django/db/backends/oracle/operations.py4
-rw-r--r--tests/expressions/tests.py8
2 files changed, 11 insertions, 1 deletions
diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py
index df3710f66b..74b1e62b7c 100644
--- a/django/db/backends/oracle/operations.py
+++ b/django/db/backends/oracle/operations.py
@@ -6,7 +6,7 @@ from functools import lru_cache
from django.conf import settings
from django.db.backends.base.operations import BaseDatabaseOperations
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.utils import DatabaseError
from django.utils import timezone
@@ -625,4 +625,6 @@ END;
return True
if isinstance(expression, ExpressionWrapper) and isinstance(expression.expression, Q):
return True
+ if isinstance(expression, RawSQL) and expression.conditional:
+ return True
return False
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index f50c634014..39dc2680fc 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -91,6 +91,14 @@ class BasicExpressionsTests(TestCase):
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):
# We can filter on attribute relationships on same model obj, e.g.
# find companies where the number of employees is greater