]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- used a metaclass trick to get Session.bind / Session.<someprop> to work
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Aug 2007 01:18:42 +0000 (01:18 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Aug 2007 01:18:42 +0000 (01:18 +0000)
lib/sqlalchemy/orm/sessionmaker.py
test/orm/unitofwork.py

index 42064c5b80b7eb6380cf55b342f69b01d8f995d9..adf80f9a7bb69e403bec084cb305debed12bf9fb 100644 (file)
@@ -65,7 +65,20 @@ def sessionmaker(autoflush, transactional, bind=None, scope=None, enhance_classe
             global_extensions.append(SessionContextExt())
             
         default_scope=scope
+        
+        class ScopedProps(type):
+            pass
+        def makeprop(name):
+            def set(self, attr):
+                setattr(registry(), name, attr)
+            def get(self):
+                return getattr(registry(), name)
+            return property(get, set)
+        for prop in ('bind', 'dirty', 'identity_map'):
+            setattr(ScopedProps, prop, makeprop(prop))
+            
         class ScopedSess(Sess):
+            __metaclass__ = ScopedProps
             def __new__(cls, **kwargs):
                 if len(kwargs):
                     scope = kwargs.pop('scope', default_scope)
index a3e025586c1173ae20e37877a0c6db35664613f5..a3ee0654e57845630ff42281f38bf7a78e85a8d6 100644 (file)
@@ -750,7 +750,7 @@ class OneToManyTest(UnitOfWorkTest):
         Session.commit()
         Session.delete(u)
         Session.commit()
-        self.assert_(a.address_id is not None and a.user_id is None and not Session().identity_map.has_key(u._instance_key) and Session().identity_map.has_key(a._instance_key))
+        self.assert_(a.address_id is not None and a.user_id is None and not Session.identity_map.has_key(u._instance_key) and Session.identity_map.has_key(a._instance_key))
 
     def testonetoone(self):
         m = mapper(User, users, properties = dict(
@@ -867,7 +867,7 @@ class SaveTest(UnitOfWorkTest):
         # change first users name and save
         Session.update(u)
         u.user_name = 'modifiedname'
-        assert u in Session().dirty
+        assert u in Session.dirty
         Session.commit()
 
         # select both