From: Mike Bayer Date: Tue, 14 Mar 2006 16:56:05 +0000 (+0000) Subject: fixed attributes bug where if an object is committed, its lazy-loaded list got X-Git-Tag: rel_0_1_5~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbf9f191ec10067d282df63f4c684af2c00d8110;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fixed attributes bug where if an object is committed, its lazy-loaded list got blown away if it hadnt been loaded --- diff --git a/CHANGES b/CHANGES index 6d73ccaba9..3ac27f1999 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +0.1.5 +- fixed attributes bug where if an object is committed, its lazy-loaded list got +blown away if it hadnt been loaded + 0.1.4 - create_engine() now uses genericized parameters; host/hostname, db/dbname/database, password/passwd, etc. for all engine connections. makes engine URIs much more "universal" diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py index a41cdac9df..b03ead1c2e 100644 --- a/lib/sqlalchemy/attributes.py +++ b/lib/sqlalchemy/attributes.py @@ -214,7 +214,7 @@ class CallableProp(object): value = None p = self.manager.create_list(self.obj, self.key, value, readonly=self.live, **self.kwargs) - if not self.live: + if not self.live and not passive: # set the new history list as the new attribute, discards ourself self.manager.attribute_history(self.obj)[self.key] = p self.manager = None diff --git a/test/objectstore.py b/test/objectstore.py index 312e1b53f1..6a3a16f778 100644 --- a/test/objectstore.py +++ b/test/objectstore.py @@ -386,6 +386,26 @@ class SaveTest(AssertMixin): self.assert_(u.user_id == userlist[0].user_id and userlist[0].user_name == 'modifiedname') self.assert_(u2.user_id == userlist[1].user_id and userlist[1].user_name == 'savetester2') + def testlazyattrcommit(self): + """tests that when a lazy-loaded list is unloaded, and a commit occurs, that the + 'passive' call on that list does not blow away its value""" + m1 = mapper(User, users, properties = { + 'addresses': relation(mapper(Address, addresses)) + }) + + u = User() + u.addresses.append(Address()) + u.addresses.append(Address()) + u.addresses.append(Address()) + u.addresses.append(Address()) + objectstore.commit() + objectstore.clear() + ulist = m1.select() + u1 = ulist[0] + u1.user_name = 'newname' + objectstore.commit() + self.assert_(len(u1.addresses) == 4) + def testinherits(self): m1 = mapper(User, users)