]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed backref bug where you could not del instance.attr if attr
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Dec 2007 17:55:25 +0000 (17:55 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 4 Dec 2007 17:55:25 +0000 (17:55 +0000)
was None

CHANGES
lib/sqlalchemy/orm/attributes.py
test/orm/attributes.py

diff --git a/CHANGES b/CHANGES
index e3ce282cfb6c4972bfbca55d51d3f2aa35adbb91..dea30fd21820b98801a07cd36ca71e04ad4199f1 100644 (file)
--- 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(), 
index 5e3747e002e5b164e81653658e29b5da83d6355f..8268d0816c511747337f78dafdf4f8e424c87b6e 100644 (file)
@@ -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."""
index 88c353cd13fd1e475b35e88903068667092a607f..4e41f0a2951e28aa96b71e165d44c08611d2490c 100644 (file)
@@ -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