From 0aacbdcf27b258387643b033352e99e6103abda8 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Fri, 23 Apr 2021 16:32:53 +0200 Subject: [PATCH] Refs #32673 -- Fixed lookups crash when comparing against lookups on Oracle. Follow up to 170b006ce82b0ecf26dc088f832538b747ca0115. --- django/db/backends/oracle/features.py | 4 ---- django/db/models/lookups.py | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/django/db/backends/oracle/features.py b/django/db/backends/oracle/features.py index 712c56de01..07f16eee71 100644 --- a/django/db/backends/oracle/features.py +++ b/django/db/backends/oracle/features.py @@ -87,10 +87,6 @@ class DatabaseFeatures(BaseDatabaseFeatures): 'Raises ORA-00600: internal error code.': { 'model_fields.test_jsonfield.TestQuerying.test_usage_in_subquery', }, - "Oracle doesn't allow filters to be compared to another expression in " - "the WHERE clause.": { - 'lookup.tests.LookupTests.test_lookup_rhs', - }, } django_test_expected_failures = { # A bug in Django/cx_Oracle with respect to string handling (#23843). diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py index c55208598c..5089737034 100644 --- a/django/db/models/lookups.py +++ b/django/db/models/lookups.py @@ -3,7 +3,7 @@ import math from copy import copy from django.core.exceptions import EmptyResultSet -from django.db.models.expressions import Case, Exists, Func, Value, When +from django.db.models.expressions import Case, Func, Value, When from django.db.models.fields import ( CharField, DateTimeField, Field, IntegerField, UUIDField, ) @@ -124,12 +124,12 @@ class Lookup: raise NotImplementedError def as_oracle(self, compiler, connection): - # Oracle doesn't allow EXISTS() to be compared to another expression - # unless it's wrapped in a CASE WHEN. + # Oracle doesn't allow EXISTS() and filters to be compared to another + # expression unless they're wrapped in a CASE WHEN. wrapped = False exprs = [] for expr in (self.lhs, self.rhs): - if isinstance(expr, Exists): + if connection.ops.conditional_expression_supported_in_where_clause(expr): expr = Case(When(expr, then=True), default=False) wrapped = True exprs.append(expr)