From: Mike Bayer Date: Tue, 24 Apr 2012 15:16:03 +0000 (-0400) Subject: - [bug] removed legacy behavior whereby X-Git-Tag: rel_0_8_0b1~469 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5c5634c04f6c64c8c95469d4c05ed4adaf5eabe2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - [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] --- diff --git a/CHANGES b/CHANGES index 0287e87669..a2094fe347 100644 --- 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 diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index 3366d5fab7..a63f10251e 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -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): diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py index 74e96c8efa..6ae0dfc451 100644 --- a/test/dialect/test_mssql.py +++ b/test/dialect/test_mssql.py @@ -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): diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 6e945aa72c..96414f07a8 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -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 = , 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())