From 9caa92b96fef0b3e6d9d280407bc6a092a77b584 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 21 Oct 2013 16:49:46 -0400 Subject: - A :func:`.bindparam` construct with a "null" type (e.g. no type specified) is now copied when used in a typed expression, and the new copy is assigned the actual type of the compared column. Previously, this logic would occur on the given :func:`.bindparam` in place. Additionally, a similar process now occurs for :func:`.bindparam` constructs passed to :meth:`.ValuesBase.values` for a :class:`.Insert` or :class:`.Update` construct. [ticket:2850] --- lib/sqlalchemy/sql/compiler.py | 24 +++++++++++++++--------- lib/sqlalchemy/sql/default_comparator.py | 5 +---- 2 files changed, 16 insertions(+), 13 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 5c7a29f99..f526203ac 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1934,16 +1934,22 @@ class SQLCompiler(Compiled): if not stmt._has_multi_parameters else "%s_0" % c.key ) - elif c.primary_key and implicit_returning: - self.returning.append(c) - value = self.process(value.self_group(), **kw) - elif implicit_return_defaults and \ - c in implicit_return_defaults: - self.returning.append(c) - value = self.process(value.self_group(), **kw) else: - self.postfetch.append(c) - value = self.process(value.self_group(), **kw) + if isinstance(value, elements.BindParameter) and \ + value.type._isnull: + value = value._clone() + value.type = c.type + + if c.primary_key and implicit_returning: + self.returning.append(c) + value = self.process(value.self_group(), **kw) + elif implicit_return_defaults and \ + c in implicit_return_defaults: + self.returning.append(c) + value = self.process(value.self_group(), **kw) + else: + self.postfetch.append(c) + value = self.process(value.self_group(), **kw) values.append((c, value)) elif self.isinsert: diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py index c9125108a..7c803ac4c 100644 --- a/lib/sqlalchemy/sql/default_comparator.py +++ b/lib/sqlalchemy/sql/default_comparator.py @@ -261,10 +261,7 @@ class _DefaultColumnComparator(operators.ColumnOperators): if isinstance(other, (ColumnElement, TextClause)): if isinstance(other, BindParameter) and \ other.type._isnull: - # TODO: perhaps we should not mutate the incoming - # bindparam() here and instead make a copy of it. - # this might be the only place that we're mutating - # an incoming construct. + other = other._clone() other.type = expr.type return other elif hasattr(other, '__clause_element__'): -- cgit v1.2.1