]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] removed legacy behavior whereby
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Apr 2012 15:16:03 +0000 (11:16 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 24 Apr 2012 15:16:03 +0000 (11:16 -0400)
a column comparison to a scalar SELECT via
== would coerce to an IN with the SQL server
dialect.  This is implicit
behavior which fails in other scenarios
so is removed.  Code which relies on this
needs to be modified to use column.in_(select)
explicitly.  [ticket:2277]

CHANGES
lib/sqlalchemy/dialects/mssql/base.py
test/dialect/test_mssql.py
test/orm/test_query.py

diff --git a/CHANGES b/CHANGES
index 0287e876691f458b6f47438f27f0f1873d034f3c..a2094fe347d528dac19b4b56bbc6738a4d9df422 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -136,6 +136,15 @@ those which apply to an 0.7 release are noted.
     also in 0.7.7.
 
 - mssql
+  - [bug] removed legacy behavior whereby 
+    a column comparison to a scalar SELECT via 
+    == would coerce to an IN with the SQL server
+    dialect.  This is implicit
+    behavior which fails in other scenarios
+    so is removed.  Code which relies on this
+    needs to be modified to use column.in_(select)
+    explicitly.  [ticket:2277]
+
   - [feature] Added interim create_engine flag
     supports_unicode_binds to PyODBC dialect,
     to force whether or not the dialect
index 3366d5fab78bb0f3030b1b57db070aa0b1ddcb05..a63f10251ee917fffc80d90b658b8bf362bd50f3 100644 (file)
@@ -158,29 +158,6 @@ following ALTER DATABASE commands executed at the SQL prompt::
 Background on SQL Server snapshot isolation is available at
 http://msdn.microsoft.com/en-us/library/ms175095.aspx.
 
-Scalar Select Comparisons
--------------------------
-
-The MSSQL dialect contains a legacy behavior whereby comparing
-a scalar select to a value using the ``=`` or ``!=`` operator
-will resolve to IN or NOT IN, respectively.  This behavior is 
-deprecated and will be removed in 0.8 - the ``s.in_()``/``~s.in_()`` operators 
-should be used when IN/NOT IN are desired.
-
-For the time being, the existing behavior prevents a comparison
-between scalar select and another value that actually wants to use ``=``.
-To remove this behavior in a forwards-compatible way, apply this
-compilation rule by placing the following code at the module import
-level::
-
-    from sqlalchemy.ext.compiler import compiles
-    from sqlalchemy.sql.expression import _BinaryExpression
-    from sqlalchemy.sql.compiler import SQLCompiler
-
-    @compiles(_BinaryExpression, 'mssql')
-    def override_legacy_binary(element, compiler, **kw):
-        return SQLCompiler.visit_binary(compiler, element, **kw)
-
 Known Issues
 ------------
 
@@ -906,31 +883,7 @@ class MSSQLCompiler(compiler.SQLCompiler):
                                                              binary.left, 
                                                              binary.operator), 
                                 **kwargs)
-        else:
-            if (
-                (binary.operator is operator.eq or 
-                binary.operator is operator.ne) 
-                and (
-                    (isinstance(binary.left, expression._FromGrouping) 
-                     and isinstance(binary.left.element, 
-                                    expression._ScalarSelect)) 
-                    or (isinstance(binary.right, expression._FromGrouping) 
-                        and isinstance(binary.right.element, 
-                                       expression._ScalarSelect)) 
-                    or isinstance(binary.left, expression._ScalarSelect) 
-                    or isinstance(binary.right, expression._ScalarSelect)
-                    )
-               ):
-                op = binary.operator == operator.eq and "IN" or "NOT IN"
-                util.warn_deprecated("Comparing a scalar select using ``=``/``!=`` will "
-                                    "no longer produce IN/NOT IN in 0.8.  To remove this "
-                                    "behavior immediately, use the recipe at "
-                        "http://www.sqlalchemy.org/docs/07/dialects/mssql.html#scalar-select-comparisons")
-                return self.process(
-                        expression._BinaryExpression(binary.left,
-                                                     binary.right, op),
-                                    **kwargs)
-            return super(MSSQLCompiler, self).visit_binary(binary, **kwargs)
+        return super(MSSQLCompiler, self).visit_binary(binary, **kwargs)
 
     def returning_clause(self, stmt, returning_cols):
 
index 74e96c8efa53e56c60dd0f5b1a4b67f319b7356f..6ae0dfc451148fe014d950fb69f2eb97fbd05310 100644 (file)
@@ -183,10 +183,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
         ]:
             self.assert_compile(expr, compile, dialect=mxodbc_dialect)
 
-    @testing.uses_deprecated
     def test_in_with_subqueries(self):
-        """Test that when using subqueries in a binary expression
-        the == and != are changed to IN and NOT IN respectively.
+        """Test removal of legacy behavior that converted "x==subquery"
+        to use IN.
 
         """
 
@@ -194,14 +193,14 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
         self.assert_compile(t.select().where(t.c.somecolumn
                             == t.select()),
                             'SELECT sometable.somecolumn FROM '
-                            'sometable WHERE sometable.somecolumn IN '
+                            'sometable WHERE sometable.somecolumn = '
                             '(SELECT sometable.somecolumn FROM '
                             'sometable)')
         self.assert_compile(t.select().where(t.c.somecolumn
                             != t.select()),
                             'SELECT sometable.somecolumn FROM '
-                            'sometable WHERE sometable.somecolumn NOT '
-                            'IN (SELECT sometable.somecolumn FROM '
+                            'sometable WHERE sometable.somecolumn != '
+                            '(SELECT sometable.somecolumn FROM '
                             'sometable)')
 
     def test_count(self):
index 6e945aa72c0c16e65e11b2913b5394c559f9e439..96414f07a8f75982c6c019aec570d4c3a22e6abb 100644 (file)
@@ -822,7 +822,6 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
                             'IN (SELECT users.id FROM users WHERE '
                             'users.id = :id_1)')
 
-    @testing.fails_on('mssql', "mssql doesn't allow col = <subquery>, sqla deprecated workaround")
     def test_param_transfer(self):
         User = self.classes.User
 
@@ -830,7 +829,7 @@ class ExpressionTest(QueryTest, AssertsCompiledSQL):
 
         q = session.query(User.id).filter(User.id==bindparam('foo')).params(foo=7).subquery()
 
-        q = session.query(User).filter(User.id==q)
+        q = session.query(User).filter(User.id.in_(q))
 
         eq_(User(id=7), q.one())