From adb3a302ef1f25ae41b2a83ce857e3ed2613c84d Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Wed, 5 May 2021 22:06:19 +0200 Subject: [PATCH] Add a comment in the compiler on why the NOT IN operator is rendered using brackets. Change-Id: I39c2e6a03e8aad7ff27bc6000da5bc9f1de14dc2 --- lib/sqlalchemy/sql/compiler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 437a11a607..dedd75f5cb 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1908,6 +1908,9 @@ class SQLCompiler(Compiled): return self._render_in_expr_w_bindparam(binary, operator, **kw) def visit_not_in_op_binary(self, binary, operator, **kw): + # The brackets are required in the NOT IN operation because the empty + # case is handled using the form "(col NOT IN (null) OR 1 = 1)". + # The presence of the OR makes the brackets required. return "(%s)" % self._render_in_expr_w_bindparam( binary, operator, **kw ) -- 2.47.3