From: Jason Kirtland Date: Tue, 9 Feb 2010 22:38:00 +0000 (+0000) Subject: Fix instance.__eq__() regression in orm attributes. X-Git-Tag: rel_0_6beta2~215 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5e2b2bbd95106cfc60df532da3f215f14da82961;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix instance.__eq__() regression in orm attributes. --- diff --git a/CHANGES b/CHANGES index 13c5322ff2..27f3243a27 100644 --- a/CHANGES +++ b/CHANGES @@ -33,7 +33,10 @@ CHANGES returned statement, thus avoiding various SQL composition errors which can result from column name conflicts. [ticket:1676] - + + - Fixed bug in attribute history that inadvertently invoked + __eq__ on mapped instances. + - sql - Added math negation operator support, -x. diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 574df7d91a..662059af40 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -590,7 +590,9 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl): def fire_replace_event(self, state, dict_, value, previous, initiator): if self.trackparent: - if previous is not value and previous not in (None, PASSIVE_NO_RESULT): + if (previous is not value and + previous is not None and + previous is not PASSIVE_NO_RESULT): self.sethasparent(instance_state(previous), False) for ext in self.extensions: @@ -823,7 +825,7 @@ class GenericBackrefExtension(interfaces.AttributeExtension): def set(self, state, child, oldchild, initiator): if oldchild is child: return child - if oldchild not in (None, PASSIVE_NO_RESULT): + if oldchild is not None and oldchild is not PASSIVE_NO_RESULT: # With lazy=None, there's no guarantee that the full collection is # present when updating via a backref. old_state, old_dict = instance_state(oldchild), instance_dict(oldchild) @@ -1244,10 +1246,16 @@ class History(tuple): def as_state(self): return History( - [c not in (None, PASSIVE_NO_RESULT) and instance_state(c) or None for c in self.added], - [c not in (None, PASSIVE_NO_RESULT) and instance_state(c) or None for c in self.unchanged], - [c not in (None, PASSIVE_NO_RESULT) and instance_state(c) or None for c in self.deleted], - ) + [(c is not None and c is not PASSIVE_NO_RESULT) + and instance_state(c) or None + for c in self.added], + [(c is not None and c is not PASSIVE_NO_RESULT) + and instance_state(c) or None + for c in self.unchanged], + [(c is not None and c is not PASSIVE_NO_RESULT) + and instance_state(c) or None + for c in self.deleted], + ) @classmethod def from_attribute(cls, attribute, state, current): @@ -1271,7 +1279,9 @@ class History(tuple): ) else: if current is NO_VALUE: - if original not in [None, NEVER_SET, NO_VALUE]: + if (original is not None and + original is not NEVER_SET and + original is not NO_VALUE): deleted = [original] else: deleted = ()