From: Mike Bayer Date: Tue, 4 Dec 2007 17:55:25 +0000 (+0000) Subject: - fixed backref bug where you could not del instance.attr if attr X-Git-Tag: rel_0_4_2~112 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=c6bda7dcc89ae5f7842f0e900d3917024a74eb29;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - fixed backref bug where you could not del instance.attr if attr was None --- diff --git a/CHANGES b/CHANGES index e3ce282cfb..dea30fd218 100644 --- a/CHANGES +++ b/CHANGES @@ -38,6 +38,9 @@ CHANGES ColumnElement is accepted now, as the compiler auto-labels non-labeled ColumnElements now. a selectable, like a select() statement, still requires conversion to ColumnElement via as_scalar() or label(). + + - fixed backref bug where you could not del instance.attr if attr + was None - several ORM attributes have been removed or made private: mapper.get_attr_by_column(), mapper.set_attr_by_column(), diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 5e3747e002..8268d0816c 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -564,7 +564,8 @@ class GenericBackrefExtension(interfaces.AttributeExtension): getattr(child.__class__, self.key).impl.append(child._state, instance, initiator) def remove(self, instance, child, initiator): - getattr(child.__class__, self.key).impl.remove(child._state, instance, initiator) + if child is not None: + getattr(child.__class__, self.key).impl.remove(child._state, instance, initiator) class ClassState(object): """tracks state information at the class level.""" diff --git a/test/orm/attributes.py b/test/orm/attributes.py index 88c353cd13..4e41f0a295 100644 --- a/test/orm/attributes.py +++ b/test/orm/attributes.py @@ -203,6 +203,10 @@ class AttributesTest(PersistTest): p4.blog = b self.assert_(b.posts == [p1, p2, p4]) + # assert no failure removing None + p5 = Post() + p5.blog = None + del p5.blog class Port(object):pass class Jack(object):pass