summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/elements.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-04-07 21:43:17 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-04-08 10:29:08 -0400
commitdf078a6fb010e28cb14afa1f0947add1f60e0e52 (patch)
treecebfa19139094d45347373bfdc830c8f675881f1 /lib/sqlalchemy/sql/elements.py
parent4d21920638af4729b6ff09b1ac8c3a20878bd922 (diff)
downloadsqlalchemy-df078a6fb010e28cb14afa1f0947add1f60e0e52.tar.gz
Infer types in BindParameter when expanding=True
Enhanced the "expanding" feature used for :meth:`_sql.ColumnOperators.in_` operations to infer the type of expression from the right hand list of elements, if the left hand side does not have any explicit type set up. This allows the expression to support stringification among other things. In 1.3, "expanding" was not automatically used for :meth:`_sql.ColumnOperators.in_` expressions, so in that sense this change fixes a behavioral regression. Fixes: #6222 Change-Id: Icdfda1e2c226a21896cafd6d8f251547794451c2
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r--lib/sqlalchemy/sql/elements.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index dfa6c0f8f..9e1b69088 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -1392,15 +1392,26 @@ class BindParameter(roles.InElementRole, ColumnElement):
self.literal_execute = literal_execute
if _is_crud:
self._is_crud = True
+
if type_ is None:
+ if expanding and value:
+ check_value = value[0]
+ else:
+ check_value = value
if _compared_to_type is not None:
self.type = _compared_to_type.coerce_compared_value(
- _compared_to_operator, value
+ _compared_to_operator, check_value
)
else:
- self.type = type_api._resolve_value_to_type(value)
+ self.type = type_api._resolve_value_to_type(check_value)
elif isinstance(type_, type):
self.type = type_()
+ elif type_._is_tuple_type:
+ if expanding and value:
+ check_value = value[0]
+ else:
+ check_value = value
+ self.type = type_._resolve_values_to_types(check_value)
else:
self.type = type_