From 5b8738b7e390471bd31b9ece90d0a3fd7653d859 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 6 Jul 2011 12:35:45 -0400 Subject: - The join condition produced by with_parent as well as when using a "dynamic" relationship against a parent will generate unique bindparams, rather than incorrectly repeating the same bindparam. [ticket:2207]. Also in 0.6.9. --- lib/sqlalchemy/sql/expression.py | 9 +++++++++ lib/sqlalchemy/sql/util.py | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 66a87c26f..071bb3c50 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2498,7 +2498,16 @@ class _BindParamClause(ColumnElement): else: self.key = key or _generated_label('%%(%d param)s' % id(self)) + + # identifiying key that won't change across + # clones, used to identify the bind's logical + # identity + self._identifying_key = self.key + + # key that was passed in the first place, used to + # generate new keys self._orig_key = key or 'param' + self.unique = unique self.value = value self.callable = callable_ diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index f003a9691..77c3e45ec 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -194,13 +194,15 @@ def adapt_criterion_to_null(crit, nulls): """given criterion containing bind params, convert selected elements to IS NULL.""" def visit_binary(binary): - if isinstance(binary.left, expression._BindParamClause) and binary.left.key in nulls: + if isinstance(binary.left, expression._BindParamClause) \ + and binary.left._identifying_key in nulls: # reverse order if the NULL is on the left side binary.left = binary.right binary.right = expression.null() binary.operator = operators.is_ binary.negate = operators.isnot - elif isinstance(binary.right, expression._BindParamClause) and binary.right.key in nulls: + elif isinstance(binary.right, expression._BindParamClause) \ + and binary.right._identifying_key in nulls: binary.right = expression.null() binary.operator = operators.is_ binary.negate = operators.isnot -- cgit v1.2.1