]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- unit test for strong refs
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 9 Dec 2006 02:46:09 +0000 (02:46 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 9 Dec 2006 02:46:09 +0000 (02:46 +0000)
- unit test to test [ticket:354]

lib/sqlalchemy/orm/session.py
test/orm/session.py
test/orm/unitofwork.py

index 1d872c8c4f6af019830d9272fb1d5744ae929acb..888d92eb9d80859d7e47698bb4e30a8124b77d65 100644 (file)
@@ -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()"""
index 5cb7009bb56bfae3e97cd9318e0d0e222aaa1f9b..48b6a9c7daa25627ddb2f70bfd9f9cc86d360fb1 100644 (file)
@@ -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)
index faead64f077f98d16652bf4a0f7040bc9f13c28e..700597e08d3913036abb356e8ba0b56a31f246cc 100644 (file)
@@ -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."""