Skip to content

Commit

Permalink
Fixed #20091 -- Oracle null promotion for empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
akaariai committed Mar 24, 2013
1 parent 9c4882b commit be3f1d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions django/db/models/sql/query.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1078,6 +1078,11 @@ def build_filter(self, filter_expr, branch_negated=False, current_negated=False,
elif isinstance(value, ExpressionNode): elif isinstance(value, ExpressionNode):
# If value is a query expression, evaluate it # If value is a query expression, evaluate it
value = SQLEvaluator(value, self, reuse=can_reuse) value = SQLEvaluator(value, self, reuse=can_reuse)
# For Oracle also '' is equivalent to null.
if (lookup_type == 'exact' and value == '' and
connections[DEFAULT_DB_ALIAS].features.interprets_empty_strings_as_nulls):
value = True
lookup_type = 'isnull'


for alias, aggregate in self.aggregates.items(): for alias, aggregate in self.aggregates.items():
if alias in (parts[0], LOOKUP_SEP.join(parts)): if alias in (parts[0], LOOKUP_SEP.join(parts)):
Expand Down
9 changes: 8 additions & 1 deletion tests/queries/tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1785,7 +1785,6 @@ def test_tickets_8921_9188(self):


# Nested queries are possible (although should be used with care, since # Nested queries are possible (although should be used with care, since
# they have performance problems on backends like MySQL. # they have performance problems on backends like MySQL.

self.assertQuerysetEqual( self.assertQuerysetEqual(
Annotation.objects.filter(notes__in=Note.objects.filter(note="n1")), Annotation.objects.filter(notes__in=Note.objects.filter(note="n1")),
['<Annotation: a1>'] ['<Annotation: a1>']
Expand Down Expand Up @@ -2824,3 +2823,11 @@ def test_ticket_20101(self):
self.assertTrue(n in qs1) self.assertTrue(n in qs1)
self.assertFalse(n in qs2) self.assertFalse(n in qs2)
self.assertTrue(n in (qs1 | 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))

0 comments on commit be3f1d3

Please sign in to comment.