From: Mike Bayer Date: Tue, 2 Sep 2008 16:07:46 +0000 (+0000) Subject: - Fixed custom instrumentation bug whereby get_instance_dict() X-Git-Tag: rel_0_5rc1~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d578d67035c519d4205e757c926392896e6a57e7;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed custom instrumentation bug whereby get_instance_dict() was not called for newly constructed instances not loaded by the ORM. --- diff --git a/CHANGES b/CHANGES index 989fa0200b..1204a347c2 100644 --- 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 diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index e67026eead..ddebc563f0 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -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""" diff --git a/test/orm/extendedattr.py b/test/orm/extendedattr.py index 8602f26815..4914bbd709 100644 --- a/test/orm/extendedattr.py +++ b/test/orm/extendedattr.py @@ -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):