- changed milestone to 0.7.8
Can't do `xxx.in_([None])` with MSSQLStrictCompiler
Issue #2496
resolved
With MSSQLStrictCompiler, adding a xxx.in_([None](None))
filter to a query will cause error:
This is caused by the `if bindparam.value is None:` checking in source:lib/sqlalchemy/sql/compiler.py. If I remove the checking, then the query works fine. Is it safe to remove the checking?
Also, I am using mssql+pyodbc with MSSQLStrictCompiler, which I am not sure is a supported use case.
Comments (5)
-
repo owner -
reporter Well, I kind of abuse column_property, resulting in queries with 100+ bind parameters in the columns clause, which makes SQL Server Profiler output rather difficult to read. So using the strict compiler is more of a cosmetic fix for something I regret doing but too late to be changed.
Patch works. Thanks :)
-
reporter On further thought, setting ansi_bind_rules to True looks like a more fitting workaround for me, as I do want to have IN clause and NOT IN clause to be parameterized.
-
repo owner - changed status to resolved
- changed component to sql
- changed milestone to 0.8.0final
-
repo owner - removed milestone
Removing milestone: 0.8.0final (automated comment)
- Log in to comment
There is absolutely no reason you need the MSSQLStrictCompiler with pyodbc, it was designed for mxodbc which uses a particular API of ODBC that allows binds in far fewer places.
The bug here is that in_() is not expecting "None" at all, which would normally be coerced to null().
Workaround is to, well first off don't bother with the "strict" compiler, no idea what purpose that is solving, then for now just pass null() instead of None.
patch: