Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #20091 -- Oracle null promotion for empty strings

  • Loading branch information...
commit e17fa9e877e84e93b699c2bd13ea48dbbb86e451 1 parent a4b8a4b
@akaariai akaariai authored
Showing with 16 additions and 1 deletion.
  1. +8 −0 django/db/models/sql/query.py
  2. +8 −1 tests/queries/tests.py
View
8 django/db/models/sql/query.py
@@ -1078,6 +1078,14 @@ def build_filter(self, filter_expr, branch_negated=False, current_negated=False,
elif isinstance(value, ExpressionNode):
# If value is a query expression, evaluate it
value = SQLEvaluator(value, self, reuse=can_reuse)
+ # For Oracle '' is equivalent to null. The check needs to be done
+ # at this stage because join promotion can't be done at compiler
+ # stage. Using DEFAULT_DB_ALIAS isn't nice, but it is the best we
+ # can do here. Similar thing is done in is_nullable(), too.
+ if (connections[DEFAULT_DB_ALIAS].features.interprets_empty_strings_as_nulls and
+ lookup_type == 'exact' and value == ''):
+ value = True
+ lookup_type = 'isnull'
for alias, aggregate in self.aggregates.items():
if alias in (parts[0], LOOKUP_SEP.join(parts)):
View
9 tests/queries/tests.py
@@ -1785,7 +1785,6 @@ def test_tickets_8921_9188(self):
# Nested queries are possible (although should be used with care, since
# they have performance problems on backends like MySQL.
-
self.assertQuerysetEqual(
Annotation.objects.filter(notes__in=Note.objects.filter(note="n1")),
['<Annotation: a1>']
@@ -2824,3 +2823,11 @@ def test_ticket_20101(self):
self.assertTrue(n in qs1)
self.assertFalse(n in qs2)
self.assertTrue(n in (qs1 | qs2))
+
+class EmptyStringPromotionTests(TestCase):
+ def test_empty_string_promotion(self):
+ qs = RelatedObject.objects.filter(single__name='')
+ if connection.features.interprets_empty_strings_as_nulls:
+ self.assertIn('LEFT OUTER JOIN', str(qs.query))
+ else:
+ self.assertNotIn('LEFT OUTER JOIN', str(qs.query))
Please sign in to comment.
Something went wrong with that request. Please try again.