From f2cf62090c4f9812bf4a57a9f68172b1b2eafd6c Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 26 Jun 2014 14:58:42 -0400 Subject: [PATCH] - Fixed bug involving dynamic attributes, that was again a regression of :ticket:`3060` from verision 0.9.5. A self-referential relationship with lazy='dynamic' would raise a TypeError within a flush operation. fixes #3099 --- doc/build/changelog/changelog_09.rst | 8 ++++++++ lib/sqlalchemy/orm/dynamic.py | 5 +++-- test/orm/test_dynamic.py | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index 3c7772b287..56d43a9e62 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -14,6 +14,14 @@ :version: 0.9.7 :released: + .. change:: + :tags: bug, orm + :tickets: 3099 + + Fixed bug involving dynamic attributes, that was again a regression + of :ticket:`3060` from verision 0.9.5. A self-referential relationship + with lazy='dynamic' would raise a TypeError within a flush operation. + .. change:: :tags: bug, declarative :tickets: 3097 diff --git a/lib/sqlalchemy/orm/dynamic.py b/lib/sqlalchemy/orm/dynamic.py index bae09d32d5..82e0b00481 100644 --- a/lib/sqlalchemy/orm/dynamic.py +++ b/lib/sqlalchemy/orm/dynamic.py @@ -171,9 +171,10 @@ class DynamicAttributeImpl(attributes.AttributeImpl): c = self._get_collection_history(state, passive) return c.as_history() - def get_all_pending(self, state, dict_): + def get_all_pending(self, state, dict_, + passive=attributes.PASSIVE_NO_INITIALIZE): c = self._get_collection_history( - state, attributes.PASSIVE_NO_INITIALIZE) + state, passive) return [ (attributes.instance_state(x), x) for x in diff --git a/test/orm/test_dynamic.py b/test/orm/test_dynamic.py index 21dcfd436c..54ea3c2f1e 100644 --- a/test/orm/test_dynamic.py +++ b/test/orm/test_dynamic.py @@ -600,6 +600,23 @@ class UOWTest(_DynamicFixture, _fixtures.FixtureTest, def test_delete_cascade(self): self._test_delete_cascade(False) + def test_self_referential(self): + Node, nodes = self.classes.Node, self.tables.nodes + + + mapper(Node, nodes, properties={ + 'children': relationship(Node, lazy="dynamic", order_by=nodes.c.id) + }) + + sess = Session() + n2, n3 = Node(), Node() + n1 = Node(children=[n2, n3]) + sess.add(n1) + sess.commit() + + eq_(n1.children.all(), [n2, n3]) + + def test_remove_orphans(self): addresses = self.tables.addresses User, Address = self._user_address_fixture(addresses_args={ -- 2.47.3