From 307726dfd9f852e94ac1f354c78eb0f0a5ce2c86 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 9 Dec 2006 02:46:09 +0000 Subject: [PATCH] - unit test for strong refs - unit test to test [ticket:354] --- lib/sqlalchemy/orm/session.py | 2 +- test/orm/session.py | 17 +++++++++++++++++ test/orm/unitofwork.py | 14 +++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 1d872c8c4f..888d92eb9d 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -426,7 +426,7 @@ class Session(object): dirty = property(lambda s:s.uow.locate_dirty(), doc="a Set of all objects marked as 'dirty' within this Session") deleted = property(lambda s:s.uow.deleted, doc="a Set of all objects marked as 'deleted' within this Session") new = property(lambda s:s.uow.new, doc="a Set of all objects marked as 'new' within this Session.") - identity_map = property(lambda s:s.uow.identity_map, doc="a WeakValueDictionary consisting of all objects within this Session keyed to their _instance_key value.") + identity_map = property(lambda s:s.uow.identity_map, doc="a dictionary consisting of all objects within this Session keyed to their _instance_key value.") def import_instance(self, *args, **kwargs): """deprecated; a synynom for merge()""" diff --git a/test/orm/session.py b/test/orm/session.py index 5cb7009bb5..48b6a9c7da 100644 --- a/test/orm/session.py +++ b/test/orm/session.py @@ -91,6 +91,23 @@ class SessionTest(AssertMixin): s.update(user) assert user in s assert user not in s.dirty + + def test_strong_ref(self): + """test that the session is strong-referencing""" + tables.delete() + s = create_session() + class User(object):pass + mapper(User, users) + + # save user + s.save(User()) + s.flush() + user = s.query(User).selectone() + user = None + print s.identity_map + import gc + gc.collect() + assert len(s.identity_map) == 1 def test_no_save_cascade(self): mapper(Address, addresses) diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py index faead64f07..700597e08d 100644 --- a/test/orm/unitofwork.py +++ b/test/orm/unitofwork.py @@ -709,7 +709,19 @@ class SaveTest(UnitOfWorkTest): u = User() u.user_id=42 ctx.current.flush() - + + def test_dont_update_blanks(self): + mapper(User, users) + u = User() + u.user_name = "" + ctx.current.flush() + ctx.current.clear() + u = ctx.current.query(User).get(u.user_id) + u.user_name = "" + def go(): + ctx.current.flush() + self.assert_sql_count(db, go, 0) + def testmultitable(self): """tests a save of an object where each instance spans two tables. also tests redefinition of the keynames for the column properties.""" -- 2.47.2