Skip to content


Subversion checkout URL

You can clone with
Download ZIP
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 bd283aa.
  • Loading branch information...
commit e74787391e8fdf87d9a92138028911746809bd7c 1 parent f572ee0
@akaariai akaariai authored
9 django/db/models/sql/
@@ -135,10 +135,13 @@ def as_sql(self, qn, connection):
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
@charettes Collaborator

@akaariai small comment typo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ # 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):
2  tests/regressiontests/queries/
@@ -2091,7 +2091,7 @@ def test_empty_full_handling_disjunction(self):
w = WhereNode(children=[NothingNode(), self.DummyNode()], connector='OR')
self.assertEquals(w.as_sql(qn, connection), ('dummy', []))
- 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

1 comment on commit e747873


I ended up rewording the comment in ab7f071.

Please sign in to comment.
Something went wrong with that request. Please try again.