]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed custom instrumentation bug whereby get_instance_dict()
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Sep 2008 16:07:46 +0000 (16:07 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 2 Sep 2008 16:07:46 +0000 (16:07 +0000)
was not called for newly constructed instances not loaded
by the ORM.

CHANGES
lib/sqlalchemy/orm/attributes.py
test/orm/extendedattr.py

diff --git a/CHANGES b/CHANGES
index 989fa0200ba6099e69ecd8af8feb3262bb357320..1204a347c27121014c3363d77d1355e37f1dbbaf 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -84,6 +84,10 @@ CHANGES
     - Fixed bug whereby changing a primary key attribute on an 
       entity where the attribute's previous value had been expired 
       would produce an error upon flush(). [ticket:1151]
+      
+    - Fixed custom instrumentation bug whereby get_instance_dict()
+      was not called for newly constructed instances not loaded
+      by the ORM.
 
     - Session.delete() adds the given object to the session if 
       not already present.  This was a regression bug from 0.4
index e67026eead65ac829dbab1faa8e74410ed4321a7..ddebc563f09b20bf9a2ab860af8f9ed0bb472bb4 100644 (file)
@@ -1241,9 +1241,7 @@ class ClassManager(dict):
         if self.has_state(instance):
             return False
         else:
-            new_state = self.instance_state_factory(instance, self)
-            self.install_state(instance, new_state)
-            return new_state
+            return self.setup_instance(instance)
 
     def has_parent(self, state, key, optimistic=False):
         """TODO"""
index 8602f2681579b41684e873df840ec107142341aa..4914bbd709a0787c0e3ddcdc45c0bbdfe12ce70e 100644 (file)
@@ -104,6 +104,21 @@ class UserDefinedExtensionTest(_base.ORMTest):
         clear_mappers()
         attributes._install_lookup_strategy(util.symbol('native'))
 
+    def test_instance_dict(self):
+        class User(MyClass):
+            pass
+            
+        attributes.register_class(User)
+        attributes.register_attribute(User, 'user_id', uselist = False, useobject=False)
+        attributes.register_attribute(User, 'user_name', uselist = False, useobject=False)
+        attributes.register_attribute(User, 'email_address', uselist = False, useobject=False)
+            
+        u = User()
+        u.user_id = 7
+        u.user_name = 'john'
+        u.email_address = 'lala@123.com'
+        self.assert_(u.__dict__ == {'_my_state':u._my_state, '_goofy_dict':{'user_id':7, 'user_name':'john', 'email_address':'lala@123.com'}})
+        
     def test_basic(self):
         for base in (object, MyBaseClass, MyClass):
             class User(base):