Commit e7478739 authored by Anssi Kääriäinen's avatar Anssi Kääriäinen
Browse files

Fixed a regression introduced in where.as_sql() refactor

At least Oracle needs parentheses in negated where conditions, even if
there is only single condition negated. Fixed this by reverting to old
logic in that part of as_sql() and adding a comment about this.

I did not investigate why the parentheses are needed. The original
offending commit was bd283aa8.
parent f572ee0c
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -135,10 +135,13 @@ class WhereNode(tree.Node):
        conn = ' %s ' % self.connector
        sql_string = conn.join(result)
        if sql_string:
            if len(result) > 1:
                sql_string = '(%s)' % sql_string
            if self.negated:
                sql_string = 'NOT %s' % sql_string
                # Note that some backends (Oracle at least) need the
                # parentheses even around single experssion in the
                # negated case.
                sql_string = 'NOT (%s)' % sql_string
            elif len(result) > 1:
                sql_string = '(%s)' % sql_string
        return sql_string, result_params

    def make_atom(self, child, qn, connection):
+1 −1
Original line number Diff line number Diff line
@@ -2091,7 +2091,7 @@ class WhereNodeTest(TestCase):
        w = WhereNode(children=[NothingNode(), self.DummyNode()], connector='OR')
        self.assertEquals(w.as_sql(qn, connection), ('dummy', []))
        w.negate()
        self.assertEquals(w.as_sql(qn, connection), ('NOT dummy', []))
        self.assertEquals(w.as_sql(qn, connection), ('NOT (dummy)', []))

    def test_empty_nodes(self):
        qn = connection.ops.quote_name