summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/elements.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-02-27 19:54:49 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-02-27 19:54:49 -0500
commite21cd0d95fb6cdcb4e10ea78abd5626bb92c37c3 (patch)
treecf734e703d24fc415727279cb137d97858674cd7 /lib/sqlalchemy/sql/elements.py
parentc2f86c92b1fbb4e855161bd509d3057f86ed7a74 (diff)
downloadsqlalchemy-e21cd0d95fb6cdcb4e10ea78abd5626bb92c37c3.tar.gz
- Fixed bug in :func:`.tuple_` construct where the "type" of essentially
the first SQL expression would be applied as the "comparison type" to a compared tuple value; this has the effect in some cases of an inappropriate "type coersion" occurring, such as when a tuple that has a mix of String and Binary values improperly coerces target values to Binary even though that's not what they are on the left side. :func:`.tuple_` now expects heterogeneous types within its list of values. fixes #2977
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r--lib/sqlalchemy/sql/elements.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index f2ce0619c..c230fb0d3 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -1856,9 +1856,10 @@ class Tuple(ClauseList, ColumnElement):
"""
clauses = [_literal_as_binds(c) for c in clauses]
- self.type = kw.pop('type_', None)
- if self.type is None:
- self.type = _type_from_args(clauses)
+ self._type_tuple = [arg.type for arg in clauses]
+ self.type = kw.pop('type_', self._type_tuple[0]
+ if self._type_tuple else type_api.NULLTYPE)
+
super(Tuple, self).__init__(*clauses, **kw)
@property
@@ -1868,8 +1869,8 @@ class Tuple(ClauseList, ColumnElement):
def _bind_param(self, operator, obj):
return Tuple(*[
BindParameter(None, o, _compared_to_operator=operator,
- _compared_to_type=self.type, unique=True)
- for o in obj
+ _compared_to_type=type_, unique=True)
+ for o, type_ in zip(obj, self._type_tuple)
]).self_group()