summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-09-02 16:07:46 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-09-02 16:07:46 +0000
commitd578d67035c519d4205e757c926392896e6a57e7 (patch)
tree1c47ef1de153abdb112139a59abbf87342a61069
parent714e629aeb033e85fd4002bd959e10b8f2de227e (diff)
downloadsqlalchemy-d578d67035c519d4205e757c926392896e6a57e7.tar.gz
- Fixed custom instrumentation bug whereby get_instance_dict()
was not called for newly constructed instances not loaded by the ORM.
-rw-r--r--CHANGES4
-rw-r--r--lib/sqlalchemy/orm/attributes.py4
-rw-r--r--test/orm/extendedattr.py15
3 files changed, 20 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 989fa0200..1204a347c 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 e67026eea..ddebc563f 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 8602f2681..4914bbd70 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):