diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-05-13 15:43:53 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-05-15 17:26:57 -0400 |
commit | 405f6afaaa8177726428b6738f5fd331341cc74e (patch) | |
tree | 37df63eaa1ad098966e7b665fdfcd46dc2919d62 /lib/sqlalchemy/sql | |
parent | 067102a304012ce6afd0097627d5717994930488 (diff) | |
download | sqlalchemy-405f6afaaa8177726428b6738f5fd331341cc74e.tar.gz |
raise for same param name in expanding + non expanding
An informative error is raised if two individual :class:`.BindParameter`
objects share the same name, yet one is used within an "expanding" context
(typically an IN expression) and the other is not; mixing the same name in
these two different styles of usage is not supported and typically the
``expanding=True`` parameter should be set on the parameters that are to
receive list values outside of IN expressions (where ``expanding`` is set
by default).
Fixes: #8018
Change-Id: Ie707f29680eea16b9e421af93560ac1958e11a54
(cherry picked from commit f9fccdeeb6749d10aeec458f1a549906d58ddad8)
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 7393629a4..bc2d657fb 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2460,6 +2460,15 @@ class SQLCompiler(Compiled): "Bind parameter '%s' conflicts with " "unique bind parameter of the same name" % name ) + elif existing.expanding != bindparam.expanding: + raise exc.CompileError( + "Can't reuse bound parameter name '%s' in both " + "'expanding' (e.g. within an IN expression) and " + "non-expanding contexts. If this parameter is to " + "receive a list/array value, set 'expanding=True' on " + "it for expressions that aren't IN, otherwise use " + "a different parameter name." % (name,) + ) elif existing._is_crud or bindparam._is_crud: raise exc.CompileError( "bindparam() name '%s' is reserved " |