summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--lib/sqlalchemy/orm/attributes.py3
-rw-r--r--test/orm/attributes.py4
3 files changed, 9 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index e3ce282cf..dea30fd21 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 5e3747e00..8268d0816 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 88c353cd1..4e41f0a29 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