[Sqlalchemy-tickets] Issue #4220: Wrong `bindparam()` call signature in "Specifying Bound Parameter
Brought to you by:
zzzeek
From: Ilja E. <iss...@bi...> - 2018-03-20 19:00:33
|
New issue 4220: Wrong `bindparam()` call signature in "Specifying Bound Parameter Behaviors" https://bitbucket.org/zzzeek/sqlalchemy/issues/4220/wrong-bindparam-call-signature-in Ilja Everilä: In ["Specifying Bound Parameter Behaviors"](http://docs.sqlalchemy.org/en/latest/core/tutorial.html#specifying-bound-parameter-behaviors) there is: > The parameters can also be explicitly typed: > > stmt = stmt.bindparams(bindparam("x", String), bindparam("y", String)) but the call signature of [`bindparam()`](http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.bindparam) is: sqlalchemy.sql.expression.bindparam(key, value=symbol('NO_ARG'), type_=None, ...) Hence the example in the documentation would end up passing the type as the `value` argument. The error is not apparent given the example from the documentation, since the values are overridden when executing the statement, but will become apparent, if not: ``` #!python >>> stmt = text("SELECT * FROM users WHERE users.name BETWEEN :x AND :y") >>> stmt = stmt.bindparams(bindparam("x", String), bindparam("y", String)) >>> result = conn.execute(stmt) Traceback (most recent call last): File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/engine/base.py", line 1193, in _execute_context context) File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/engine/default.py", line 507, in do_execute cursor.execute(statement, parameters) sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/engine/base.py", line 948, in execute return meth(self, multiparams, params) File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/sql/elements.py", line 269, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/engine/base.py", line 1060, in _execute_clauseelement compiled_sql, distilled_params File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/engine/base.py", line 1200, in _execute_context context) File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/engine/base.py", line 1413, in _handle_dbapi_exception exc_info File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/util/compat.py", line 203, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/util/compat.py", line 186, in reraise raise value.with_traceback(tb) File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/engine/base.py", line 1193, in _execute_context context) File "/home/saarni/Work/sqlalchemy/lib/sqlalchemy/engine/default.py", line 507, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 0 - probably unsupported type. [SQL: 'SELECT * FROM users WHERE users.name BETWEEN ? AND ?'] [parameters: (<class 'sqlalchemy.sql.sqltypes.String'>, <class 'sqlalchemy.sql.sqltypes.String'>)] (Background on this error at: http://sqlalche.me/e/rvf5) ``` The example should be: stmt = stmt.bindparams(bindparam("x", type_=String), bindparam("y", type_=String)) |